我试图将图像置于表格的中心,以便它在表格的两行之间垂直居中。
以下是当前的情况:
但我希望图片位于与其左边的数字 1 相同的高度。
以下是使用的代码:
\definecolor{dblue}{RGB}{96,162,216}
\definecolor{mblue}{RGB}{208,221,240}
\definecolor{lblue}{RGB}{233,239,247}
\begin{table}[H]
\centering
\rowcolors{2}{lblue}{mblue}
\begin{tabular}{@{}|c|l|c|c|c|l|@{}}\rowcolor{dblue}
\toprule
\multicolumn{1}{|l|}{Iteration} & {\color[HTML]{000000} Design} & \multicolumn{1}{l|}{} & \multicolumn{1}{l|}{Max Stress} & \multicolumn{1}{l|}{Max Deflection} & Comment \\ \midrule
& \includegraphics[align=c,scale=0.125]{Ben/Pictures/aircraft-bearing-bracket-FEM.jpg} & Case 1 & XX & XX & XX \\ \cmidrule(l){3-6}
\multirow{-2}{*}{1} & \multirow{-2}{*}{} & Case 2 & XX & XX & XX \\ \midrule
& & Case 1 & XX & XX & XX \\ \cmidrule(l){3-6}
\multirow{-2}{*}{2} & \multirow{-2}{*}{} & Case 2 & XX & XX & XX \\ \midrule
& & Case 1 & XX & XX & XX \\ \cmidrule(l){3-6}
\multirow{-2}{*}{3} & \multirow{-2}{*}{} & Case 2 & XX & XX & XX \\ \midrule
& & Case 1 & XX & XX & XX \\ \cmidrule(l){3-6}
\multirow{-2}{*}{4} & \multirow{-2}{*}{} & Case 2 & XX & XX & XX \\ \midrule
& & Case 1 & XX & XX & XX \\ \cmidrule(l){2-6}
\multirow{-2}{*}{5} & & Case 2 & XX & XX & XX \\ \bottomrule
\end{tabular}
\end{table}
提前致谢!
答案1
现在你使用的\multirow{-2}{*}{}
地方想垂直居中的图像,并且将图像本身放置在表格的第二行中,而无需尝试将其放在多行中。可编译示例(软件包和选项是根据表格中的命令猜测的):
\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{multicol}
\usepackage{multirow}
\usepackage{booktabs}
\usepackage{graphicx}
\usepackage{graphbox}
\usepackage{cellspace}
\usepackage{float}
\usepackage{duckuments}%for the duck image
\begin{document}
\definecolor{dblue}{RGB}{96,162,216}
\definecolor{mblue}{RGB}{208,221,240}
\definecolor{lblue}{RGB}{233,239,247}
\begin{table}[H]
\centering
\rowcolors{2}{lblue}{mblue}
\begin{tabular}{@{}|c|l|c|c|c|l|@{}}\rowcolor{dblue}
\toprule
\multicolumn{1}{|l|}{Iteration} & {\color[HTML]{000000} Design} & \multicolumn{1}{l|}{} & \multicolumn{1}{l|}{Max Stress} & \multicolumn{1}{l|}{Max Deflection} & Comment \\ \midrule
& & Case 1 & XX & XX & XX \\ \cmidrule(l){3-6}
\multirow{-2}{*}{1} & \multirow{-2}{*}{\hfil\includegraphics[align=c,scale=.125]{example-image-duck}\hfil} & Case 2 & XX & XX & XX \\ \midrule
& & Case 1 & XX & XX & XX \\ \cmidrule(l){3-6}
\multirow{-2}{*}{2} & \multirow{-2}{*}{} & Case 2 & XX & XX & XX \\ \midrule
& & Case 1 & XX & XX & XX \\ \cmidrule(l){3-6}
\multirow{-2}{*}{3} & \multirow{-2}{*}{} & Case 2 & XX & XX & XX \\ \midrule
& & Case 1 & XX & XX & XX \\ \cmidrule(l){3-6}
\multirow{-2}{*}{4} & \multirow{-2}{*}{} & Case 2 & XX & XX & XX \\ \midrule
& & Case 1 & XX & XX & XX \\ \cmidrule(l){2-6}
\multirow{-2}{*}{5} & & Case 2 & XX & XX & XX \\ \bottomrule
\end{tabular}
\end{table}
\end{document}
答案2
我怀疑你正在寻找这样的东西:
\documentclass{article}
\usepackage[table]{xcolor}
\definecolor{dblue}{RGB}{96,162,216}
\definecolor{mblue}{RGB}{208,221,240}
\definecolor{lblue}{RGB}{233,239,247}
\usepackage[export]{adjustbox}
\usepackage{booktabs, multirow}
\begin{document}
\begin{table}[htb]
\centering
\rowcolors{2}{lblue}{mblue}
\begin{tabular}{@{}|c|l|c|c|c|l|@{}}
\rowcolor{dblue}
\toprule
Iteration
& Design & & Max Stress & Max Deflection & Comment \\
\midrule
& & Case 1 & XX & XX & XX \\
\cmidrule(l){3-6}
\multirow{-2.4}{*}{1}
& \multirow{-2.4}{*}{\includegraphics[scale=0.25, valign=c]{example-image-duck}}
& Case 2 & XX & XX & XX \\
\midrule
& & Case 1 & XX & XX & XX \\
\cmidrule(l){3-6}
\multirow{-2.4}{*}{2}
& \multirow{-2.4}{*}{image?}
& Case 2 & XX & XX & XX \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
但是,这个表格的外观很糟糕(当然,不符合我的口味)。我会删除所有垂直线、大部分水平线和颜色:
\documentclass{article}
\usepackage[export]{adjustbox}
\usepackage{booktabs, multirow}
\begin{document}
\begin{table}[htb]
\centering
\begin{tabular}{@{}c cc c c l @{}}
\toprule
Iteration
& \multicolumn{2}{c}{Design}
& Max Stress & Max Deflection & Comment \\
\midrule
& & Case 1 & XX & XX & XX \\
\multirow{-2.1}{*}{1}
& \multirow{-2.1}{*}{\includegraphics[scale=0.2, valign=c]{example-image-duck}}
& Case 2 & XX & XX & XX \\
\addlinespace
& & Case 1 & XX & XX & XX \\
\multirow{-2.1}{*}{2}
& \multirow{-2.1}{*}{\includegraphics[scale=0.2, valign=c]{example-image-duck}}
& Case 2 & XX & XX & XX \\
\addlinespace
& & Case 1 & XX & XX & XX \\
\multirow{-2.1}{*}{3}
& \multirow{-2.1}{*}{image?}
& Case 2 & XX & XX & XX \\
\bottomrule
\end{tabular}
\end{table}
\end{document}