考虑下面的代码:
\documentclass[a4paper]{article}
\usepackage[table]{xcolor}
\usepackage{graphicx}
\paperheight297mm
\paperwidth210mm
\textheight297mm
\textwidth180mm
\topmargin-25.4mm
\voffset0in
\oddsidemargin-17.5mm
\evensidemargin-17.5mm
\hoffset0in
\marginparsep0in
\marginparwidth0in
\headheight0in
\headsep0in
\begin{document}
\rowcolors{1}{green}{pink}
\begin{table}
\begin{tabular}{p{60mm} p{60mm} p{60mm}}
\includegraphics[height=40mm]{test.png} & 2 & 3 \\[50.8mm]
\includegraphics[height=40mm]{test.png} & 2 & 3 \\[50.8mm]
\includegraphics[height=40mm]{test.png} & 2 & 3 \\[50.8mm]
\includegraphics[height=40mm]{test.png} & 2 & 3 \\[50.8mm]
\includegraphics[height=40mm]{test.png} & 2 & 3 \\[50.8mm]
\end{tabular}
\end{table}
\end{document}
图像正在改变单元格的高度。如何防止这种情况发生以及如何使图像垂直居中?
\documentclass[a4paper]{article}
\usepackage[table]{xcolor}
\usepackage{calc}
\usepackage[top=0pt,bottom=0pt,textwidth=180mm]{geometry}
\begin{document}
\rowcolors{1}{green}{pink}
\begin{table}
\begin{tabular}{*{3}{p{60mm-2\tabcolsep}}}
\raisebox{-.5\height}{\includegraphics[height=40mm,width=50mm]{logo}} & 2 & 3 \\
\end{tabular}
\end{table}
\end{document}
您的代码以错误结束:
! Undefined control sequence.<argument>
\includegraphics[height=40mm,width=50mm]{logo} ...udegraphics[height=40mm,width=50mm]{logo}}
答案1
图像的参考点位于其边界框的底部;adjustbox
您可以使用指定不同的垂直对齐方式。还请注意使用来calc
真正获得所需的表格宽度;我使用是geometry
为了避免对页面尺寸进行复杂的计算。
\documentclass[a4paper]{article}
\usepackage[table]{xcolor}
\usepackage[export]{adjustbox}
\usepackage{calc}
\usepackage[top=0pt,bottom=0pt,textwidth=180mm]{geometry}
\begin{document}
\rowcolors{1}{green}{pink}
\begin{table}
\begin{tabular}{*{3}{p{60mm-2\tabcolsep}}}
\includegraphics[height=40mm,width=50mm,valign=c]{test.png} & 2 & 3 \\
\includegraphics[height=40mm,width=50mm,valign=c]{test.png} & 2 & 3 \\
\includegraphics[height=40mm,width=50mm,valign=c]{test.png} & 2 & 3 \\
\end{tabular}
\end{table}
\end{document}
请注意,adjustbox
使用该export
选项可以加载graphicx
包。
没有adjustbox
你得到同样的效果
\raisebox{-.5\height}{\includegraphics[height=40mm,width=50mm]{test.png}} & 2 & 3 \
(当然graphicx
需要加载)。