管理表格单元格内的文本

管理表格单元格内的文本

在 Latex 中创建表格并在特定单元格内插入文本时,如果文本很长,则结果如下:

在此处输入图片描述

即使单元格中有足够的空间来容纳整个句子。此外,我希望从单元格的右上角开始书写,而不是右下角。

此处报告了导致此错误的代码:

\begin{center}
    \begin{tabular}{ |c| c| }
    \hline
        {\includegraphics[scale=0.35,keepaspectratio]{png_Images/read_actor.png}}
        & 
        \begin{tabular}[]{@{}l@{}}
        This actor is in charge of performing the action of reading
        the image from the memory. 
        \end{tabular}
        \\ 
        \hline
        {\includegraphics[scale=0.3,keepaspectratio]{png_Images/tiling.png}} 
        & cap2  \\
        \hline
        {\includegraphics[scale=0.35,keepaspectratio]{png_Images/filter.png}} 
        & cap3  \\
        \hline
        {\includegraphics[scale=0.35,keepaspectratio]{png_Images/merge.png}}
        & cap4  \\
        \hline
        {\includegraphics[scale=0.35,keepaspectratio]{png_Images/save.png}} 
        & cap5  \\
    \hline
    \end{tabular}
\end{center}

有什么建议吗?

答案1

您可以加载adjustbox并使用valign=c\includegraphics并将m{some length} 用作第二列。最后,我使用该cellspace包在第一列的单元格周围添加了一些垂直填充。

\documentclass{article}
\usepackage{array, cellspace}
\setlength{\cellspacetoplimit}{4pt}
\setlength{\cellspacebottomlimit}{4pt}
\usepackage[demo]{graphicx}%
\usepackage[export]{adjustbox} 

\begin{document}

\begin{center}
    \begin{tabular}{ |Sc| m{0.4\linewidth}| }
    \hline
        {\includegraphics[scale=0.35,keepaspectratio, valign = c]{png_Images/read_actor.png}}
        &
        This actor is in charge of performing the action of reading
        the image from the memory.
        \\
        \hline
        {\includegraphics[scale=0.3,keepaspectratio, valign=c]{png_Images/tiling.png}}
        & cap2 \\
        \hline
        {\includegraphics[scale=0.35,keepaspectratio, valign=c]{png_Images/filter.png}}
        & cap3 \\
        \hline
        {\includegraphics[scale=0.35,keepaspectratio, valign=c]{png_Images/merge.png}}
        & cap4 \\
        \hline
        {\includegraphics[scale=0.35,keepaspectratio, valign=c]{png_Images/save.png}}
        & cap5 \\
    \hline
    \end{tabular}
\end{center}

\end{document} 

在此处输入图片描述

答案2

这是一个使用tabularx X类型列作为第二列的变体,以及不同的垂直对齐方式(valign=t。类似于伯纳德,我还使用该cellspace包在图像周围添加了对称的白色边框(=上下的白色空间等于\tabcolsep

在此处输入图片描述

\documentclass{article}
\usepackage{array, cellspace}
\setlength{\cellspacetoplimit}{\tabcolsep}
\setlength{\cellspacebottomlimit}{\tabcolsep}
\usepackage[demo]{graphicx}%
\usepackage[export]{adjustbox} 
\usepackage{tabularx}

\begin{document}

\begin{center}
    \begin{tabularx}{\textwidth}{ |Sc| X | }
    \hline
        {\includegraphics[scale=0.35,keepaspectratio, valign = t]{png_Images/read_actor.png}}
        &
        This actor is in charge of performing the action of reading
        the image from the memory.
        \\
        \hline
        {\includegraphics[scale=0.3,keepaspectratio, valign=t]{png_Images/tiling.png}}
        & cap2 \\
        \hline
        {\includegraphics[scale=0.35,keepaspectratio, valign=t]{png_Images/filter.png}}
        & cap3 \\
        \hline
        {\includegraphics[scale=0.35,keepaspectratio, valign=t]{png_Images/merge.png}}
        & cap4 \\
        \hline
        {\includegraphics[scale=0.35,keepaspectratio, valign=t]{png_Images/save.png}}
        & cap5 \\
    \hline
    \end{tabularx}
\end{center}

\end{document} 

相关内容