带有图形的表格中的文本的垂直对齐

带有图形的表格中的文本的垂直对齐

我正在创建一个表格,其中有一列全是图像。其余列中的文本放在单元格底部。如何将文本对齐到单元格的中心,同时考虑到图像?

\documentclass[12pt,a4paper]{article}
\usepackage{blindtext}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{booktabs}
\usepackage{siunitx}
\usepackage{graphicx}
\usepackage{multicol}
\begin{document}
\begin{table}[htb]
\footnotesize
\centering
\begin{tabular}{cccc}
\toprule
\multicolumn{2}{c}{\textbf{Head 1}} &
\textbf{Head 2 (\si{\cm})}          &
\textbf{Head 3 (\si{\mm})}          \\ 
\midrule
\includegraphics[width=0.15\linewidth]{example-image-a} & Text & 30 & \numrange{2,4}{4,8} \\ 
\includegraphics[width=0.15\linewidth]{example-image-a} & Text & 30 & \numrange{2,4}{4,8} \\
\includegraphics[width=0.15\linewidth]{example-image-a} & Text & 30 & \numrange{2,4}{4,8} \\
\includegraphics[width=0.15\linewidth]{example-image-a} & Text & 30 & \numrange{2,4}{4,8} \\
\bottomrule
\end{tabular}
\end{table}
\end{document}

在此处输入图片描述

答案1

您希望图像的基线位于中心而不是底部边缘,您可以这样做

\raisebox{-.5\height}{\includegraphics{...}}

或更容易使用

\usepackage[export]{adjustbox}

然后

\includegraphics[valign=m]{...}

答案2

使用\adjincludegraphicsfrom adjustbox(graphicx 包的扩展)– 并在图表之间添加一些填充:

\documentclass[12pt,a4paper]{article}
\usepackage{blindtext}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{booktabs}
\usepackage{siunitx}
\usepackage{adjustbox}
\usepackage{multicol}

\begin{document}

\begin{table}[htb]
\footnotesize
\centering
\begin{tabular}{cccc}
\toprule
\multicolumn{2}{c}{\textbf{Head 1}} &
\textbf{Head 2 (\si{\cm})} &
\textbf{Head 3 (\si{\mm})} \\
\midrule
\adjincludegraphics[width=0.15\linewidth, valign=c]{example-image-a} & Text & 30 & \numrange{2,4}{4,8} \\
\addlinespace
\adjincludegraphics[width=0.15\linewidth, valign=c]{example-image-a} & Text & 30 & \numrange{2,4}{4,8} \\
\addlinespace
\adjincludegraphics[width=0.15\linewidth, valign=c]{example-image-a} & Text & 30 & \numrange{2,4}{4,8} \\
\addlinespace
\adjincludegraphics[width=0.15\linewidth, valign=c]{example-image-a} & Text & 30 & \numrange{2,4}{4,8} \\
\bottomrule
\end{tabular}
\end{table}

\end{document}
[![enter image description here][1]][1]

答案3

作为对 David Carlisle 回答的补充。如果所有图像都有相同的选项(大小)并在其周围添加一些垂直空间以及更短的表格代码,请尝试以下操作:

\documentclass[12pt,a4paper]{article}
\usepackage{booktabs}
\usepackage{siunitx}
\usepackage{graphicx}
\usepackage[export]{adjustbox}
\newcommand\insertimage[1]{% for shorter code in table
    \includegraphics[width=0.15\linewidth,valign=m, margin=0pt 3pt 0pt 3pt]%
                    {#1}}

\begin{document}
\begin{table}[htb]
\footnotesize
\centering
\begin{tabular}{cccc}
\toprule
\multicolumn{2}{c}{\textbf{Head 1}} &
\textbf{Head 2 (\si{\cm})}          &
\textbf{Head 3 (\si{\mm})}          \\
\midrule
\insertimage{example-image-a} & Text & 30 & \numrange{2,4}{4,8} \\
\insertimage{example-image-b} & Text & 30 & \numrange{2,4}{4,8} \\
\insertimage{example-image-b} & Text & 30 & \numrange{2,4}{4,8} \\
\insertimage{example-image}   & Text & 30 & \numrange{2,4}{4,8} \\
\bottomrule
\end{tabular}
\end{table}
\end{document}

在此处输入图片描述

相关内容