帶有圖像的表格

帶有圖像的表格

我想製作一個 3 行 2 列的表格,在左列中放置文本,在右列中每行放置圖像。

我不知道如何製作這個,我已經嘗試製作一個表格,但我無法修復列寬,而且我看不到圖像(也許它們在頁面之外?)。

有人能弄清楚如何做到這一點嗎?

這就是我的意思,如下。我希望文字列的寬度比圖片列的寬度更大。

在此輸入影像描述

這是我到目前為止的程式碼。

\documentclass[11pt]{article}
\usepackage{array,graphicx}
\newcommand\rowincludegraphics[2][]{\raisebox{-0.45\height}{\includegraphics[#1]{#2}}}
\begin{document}
    \begin{table}[t]
    \begin{tabular}[t]{p{10cm}|p{10cm}}
    \textbf{Column 1} & \textbf{Column 2} \\ \hline
       Text 1 & \rowincludegraphics[scale=0.4]{figure1.jpg} \\ \hline
       Text 2 & \rowincludegraphics[scale=0.4]{figure2.jpg} \\ \hline
       Text 3 & \rowincludegraphics[scale=0.4]{figure3.jpg} \\ \hline
    \end{tabular}
    \end{table}
\end{document}

圖像現在與頂部對齊,但文字沒有。我該如何解決?如果這個問題解決,問題就解決了。謝謝。

答案1

你的文件產生

 Overfull \hbox (233.45511pt too wide) in paragraph at lines 6--12

您指定了兩列,每列 10 厘米,比頁面寬得多。只需讓列為自然寬度即可:

在此輸入影像描述

\documentclass[11pt]{article}
\usepackage{array,graphicx}
\newcommand\rowincludegraphics[2][]{\raisebox{-0.45\height}{\includegraphics[#1]{#2}}}
\begin{document}
    \begin{table}[t]
    \begin{tabular}{l|l}
    \textbf{Column 1} & \textbf{Column 2} \\ \hline
       Text 1 & \rowincludegraphics[scale=0.4]{example-image-a} \\ \hline
       Text 2 & \rowincludegraphics[scale=0.4]{example-image-b} \\ \hline
       Text 3 & \rowincludegraphics[scale=0.4]{example-image} \\ \hline
    \end{tabular}
    \end{table}
\end{document}

答案2

我將省略表格中的所有垂直線,刪除大約一半的水平線,並使用包裝的畫線宏來booktabs繪製剩餘的水平線。

並且,請確保環境tabular有機會適合文字區塊。在下面的範例中,我為第 1 列和第 2 列分別選擇了 6 公分和 7 公分的寬度。

在此輸入影像描述

\documentclass[11pt]{article}
\usepackage{booktabs,array}
\usepackage[demo]{graphicx} % omit 'demo' option in real document
\newlength\mylength
\setlength\mylength{7cm} % width of second column
\begin{document}
    \begin{table}[t]
    \begin{tabular}[t]{@{} p{6cm} p{\mylength} @{}}
    \textbf{Column 1} & \textbf{Column 2} \\ 
    \midrule \addlinespace
    Text 1 & \includegraphics[width=\mylength]{figure1.jpg} 
    \\ \addlinespace
    Text 2 & \includegraphics[width=\mylength]{figure2.jpg} 
    \\ \addlinespace
    Text 3 & \includegraphics[width=\mylength]{figure3.jpg} 
    \\ \bottomrule
    \end{tabular}
    \end{table}
\end{document}

相關內容