PdfLaTeX含图片表格自动换行及图文居中对齐问题
PdfLaTeX图文表格排版问题解决方案
依赖包前置引入
首先需要在导言区添加以下两个包:
\usepackage{tabularx} % 用于自适应列宽表格 \usepackage{adjustbox} % 用于图片垂直对齐
问题1:长文本无法自动换行解决
原有代码中LLL列格式为无固定宽度的左对齐列,系统不会自动触发折行逻辑。将表格替换为tabularx环境,给需要折行的列设置自适应宽度即可:
- 第一列迭代序号固定宽度设为1cm(可按需调整)
- 第二列图片固定宽度设为0.4\textwidth
- 第三列备注使用
X格式,自动填充剩余宽度并支持自动折行
问题2:图文垂直居中且不重叠解决
不要手动使用\raisebox调整高度,直接给\includegraphics添加valign=c参数(由adjustbox包提供),会自动将图片与行内其他内容沿中心线对齐,同时自动计算行高,不会出现跨行图片重叠问题。
修正后完整代码
\begin{table*}[pos=h] \caption{This is a caption.} \begin{tabularx}{\textwidth}{@{} p{1cm} p{0.4\textwidth} X @{} } \toprule Iterations & Samples & Comments \\ \midrule 0 & \includegraphics[width=\linewidth,valign=c]{000000.png} & Training started \\ 8 & \includegraphics[width=\linewidth,valign=c]{000008.png} & The text is toooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo long that not all the contents can be shown \\ 16 & \includegraphics[width=\linewidth,valign=c]{000016.png} & \\ 32 & \includegraphics[width=\linewidth,valign=c]{000032.png} & \\ 64 & \includegraphics[width=\linewidth,valign=c]{000064.png} & \\ 128 & \includegraphics[width=\linewidth,valign=c]{000128.png} & \\ 192 & \includegraphics[width=\linewidth,valign=c]{000192.png} & \\ \bottomrule \end{tabularx} \label{tab4} \end{table*}
内容的提问来源于stack exchange,提问作者Tim
相关产品推荐
相关产品推荐

