我有一张图片表,每行旁边都有标签。我想让这些标签与它们对应的图像垂直对齐。我找到并尝试过的所有解决方案都失败了。请参阅下面的 MWE
\documentclass{article}
\usepackage{tabularx}
\usepackage{array}
\usepackage{graphicx}
\usepackage{multirow}
\begin{document}
% set width for all the figures
\newlength{\recircfigwidth}
\setlength{\recircfigwidth}{3cm}
\begin{figure*}
\renewcommand{\tabularxcolumn}[1]{m{#1}}
\centering
\begin{tabular}{m{1cm}|ccc}
\multirow{2}{*}{\(\phi\ [^\circ]\)} & \multicolumn{3}{c}{Swirl Strength [\%]} \\ \cline{2-4}
& 100 & 150 & 200 \\ \hline
15 &
\includegraphics[width=\recircfigwidth]{example-image} &
\includegraphics[width=\recircfigwidth]{example-image} &
\includegraphics[width=\recircfigwidth]{example-image} \\
12.5 &\includegraphics[width=\recircfigwidth]{example-image} &
\includegraphics[width=\recircfigwidth]{example-image} &
\includegraphics[width=\recircfigwidth]{example-image} \\
10 &\includegraphics[width=\recircfigwidth]{example-image} &
\includegraphics[width=\recircfigwidth]{example-image} &
\includegraphics[width=\recircfigwidth]{example-image}
\end{tabular}
\caption{Caption for the whole figure}
\label{fig:fig1} % I can do without the label too
\end{figure*}
\end{document}
答案1
您可以使用adjustbox
。我定义了一个\fixedincludegraphics
命令,它一劳永逸地声明宽度,但也允许进一步的键;对于这个应用程序,valign=c
。
我还删除了没有任何好处的垂直规则。
\documentclass{article}
\usepackage{booktabs}
\usepackage{array}
\usepackage{graphicx}
\usepackage[export]{adjustbox}
% set width for all the figures
\newlength{\recircfigwidth}
\setlength{\recircfigwidth}{3cm}
\newcommand{\fixedincludegraphics}[2][]{%
\includegraphics[width=\recircfigwidth,#1]{#2}%
}
\begin{document}
\begin{figure*}
\centering
\begin{tabular}{@{}cccc@{}}
\toprule
\(\phi\) (\(^\circ\)) & \multicolumn{3}{c}{Swirl Strength (\%)} \\
\cmidrule(l){2-4}
& 100 & 150 & 200 \\
\midrule
15 &
\fixedincludegraphics[valign=c]{example-image} &
\fixedincludegraphics[valign=c]{example-image} &
\fixedincludegraphics[valign=c]{example-image} \\
\addlinespace
12.5 &
\fixedincludegraphics[valign=c]{example-image} &
\fixedincludegraphics[valign=c]{example-image} &
\fixedincludegraphics[valign=c]{example-image} \\
\addlinespace
10 &
\fixedincludegraphics[valign=c]{example-image} &
\fixedincludegraphics[valign=c]{example-image} &
\fixedincludegraphics[valign=c]{example-image}
\end{tabular}
\caption{Caption for the whole figure}
\label{fig:fig1} % I can do without the label too
\end{figure*}
\end{document}
答案2
你可以这样做:
\documentclass{article}
\usepackage{tabularx}
\usepackage{array}
\usepackage{graphicx}
\usepackage{multirow, makecell}
\begin{document}
% set width for all the figures
\newlength{\recircfigwidth}
\setlength{\recircfigwidth}{3cm}
\begin{figure*}
\renewcommand{\tabularxcolumn}[1]{ >{\centering\arraybackslash}m{#1}}
\centering
\begin{tabularx}{\linewidth}{m{1cm}|XXX}
\multirow{2}{*}{\(\phi\ [^\circ]\)} & \multicolumn{3}{c}{Swirl Strength [\%]} \\ \cline{2-4}
& 100 & 150 & 200 \\ \hline
15 & \includegraphics[width=\recircfigwidth]{example-image} &
\includegraphics[width=\recircfigwidth]{example-image} &
\includegraphics[width=\recircfigwidth]{example-image} \\
12.5 &\includegraphics[width=\recircfigwidth]{example-image} &
\includegraphics[width=\recircfigwidth]{example-image} &
\includegraphics[width=\recircfigwidth]{example-image} \\
10 &\includegraphics[width=\recircfigwidth]{example-image} &
\includegraphics[width=\recircfigwidth]{example-image} &
\includegraphics[width=\recircfigwidth]{example-image}
\end{tabularx}
\caption{Caption for the whole figure}
\label{fig:fig1} % I can do without the label too
\end{figure*}
\end{document}