我又一次在构建最简单的表格时遇到了困难。场景:我想生成一个非常基本的表格,其中第一个单元格显示图像。但是,相邻单元格的文本应该垂直居中。
这是我迄今为止的代码:
\documentclass{scrreprt}
\usepackage{tabularx}
\begin{document}
\begin{table}
\begin{tabularx}{\textwidth}{|l | X|}
\hline
\framebox(0.2\textwidth,0.2\textwidth){Placeholder} & B \\ \hline
C & D \\
\hline
\end{tabularx}
\end{table}
\end{document}
像往常一样:提前感谢!
答案1
默认情况下,图片的底边位于基线上。
您可以使用adjustbox
包或“手工制作”命令以及m
列类型。
\documentclass{article}
\usepackage{tabularx}
\usepackage[export]{adjustbox}% for the first picture
\usepackage{lipsum} % for mock text
% for the second picture
\newcommand{\centerincludegraphics}[2][]{%
\begin{tabular}{@{}c@{}}\includegraphics[#1]{#2}\end{tabular}%
}
\begin{document}
\begin{table}[htp]
\renewcommand{\tabularxcolumn}{m}
\begin{tabularx}{\textwidth}{|l | X|}
\hline
\includegraphics[valign=c,width=3cm]{example-image} & \lipsum[1][1-3] \\
\hline
\centerincludegraphics[width=3cm]{example-image} & \lipsum[1][1-3] \\
\hline
\end{tabularx}
\end{table}
\end{document}
我个人的偏好是
\documentclass{article}
\usepackage{tabularx}
\usepackage[export]{adjustbox}
\usepackage{booktabs}
\usepackage{lipsum} % for mock text
\begin{document}
\begin{table}[htp]
\renewcommand{\tabularxcolumn}{m}
\begin{tabularx}{\textwidth}{lX}
\toprule
\includegraphics[valign=c,width=3cm]{example-image} & \lipsum[1][1-3] \\
\addlinespace
\includegraphics[valign=c,width=3cm]{example-image} & \lipsum[1][1-3] \\
\bottomrule
\end{tabularx}
\end{table}
\end{document}
甚至更好:
\documentclass{article}
\usepackage{tabularx}
\usepackage[export]{adjustbox}
\usepackage{booktabs}
\usepackage{lipsum} % for mock text
\begin{document}
\begin{table}[htp]
\begin{tabularx}{\textwidth}{lX}
\toprule
\includegraphics[width=3cm,valign=t]{example-image} & \lipsum[1][1-3] \\
\addlinespace
\includegraphics[width=3cm,valign=t]{example-image} & \lipsum[1][1-3] \\
\bottomrule
\end{tabularx}
\end{table}
\end{document}