我使用多行编写了下表
虽然据我所知,多行应该自动进行垂直对齐,但对我来说,只有在不包含图片的情况下才会发生这种情况。我想做的是将第一列单元格的内容垂直居中。有人对如何解决这个问题有什么建议吗?代码如下
\documentclass{article}
\usepackage{amsmath}
\usepackage{multirow,graphics,graphicx}
usepackage{booktabs}
\usepackage{array}
\begin{document}
\begin{table}[]
\centering
\caption{My caption}
\label{my-label}
\begin{tabular}{c|m{1.5cm}m{2cm}l}
MR & GS & Typ & Sym \\ \hline
\multirow{4}*{ 1} & \includegraphics[width=1cm, height=1cm]{F1} & Tria& \\
& \includegraphics[width=1cm, height=1cm]{F1} & Obl & \\
& \includegraphics[width=1cm, height=1cm]{F1} & Sq & \\ & \includegraphics[width=1cm, height=1cm]{F1} & Rec & \\ \hline
\multirow{2}{*}{2} & \includegraphics[width=1cm, height=1cm]{F1} & SqSnSq & \\
& \includegraphics[width=1cm, height=1cm]{F1} & TrHex & \\ \hline
\multirow{2}{*}{3} & \includegraphics[width=1cm, height=1cm]{F1} & TrKag & \\
& \includegraphics[width=1cm, height=1cm]{F1} & RecShSq& \\
\hline
\end{tabular}
\end{table}
\end{document}
答案1
我认为不使用它multirow
而只使用右侧的嵌套表格更容易,因为tabular
默认情况下是垂直居中的。
\documentclass{article}
\usepackage{amsmath}
\usepackage{multirow,graphics,graphicx}
\usepackage{booktabs}
\usepackage{array}
\begin{document}
\begin{table}
\centering
\caption{My caption}
\label{my-label}
\begin{tabular}{c|l}
MR &
\begin{tabular}[t]{@{}p{1cm}p{2cm}p{2cm}@{}}GS & Typ & Sym\end{tabular}
\\ \midrule
1 &
\begin{tabular}{@{}m{1cm}m{2cm}m{2cm}@{}}
\includegraphics[width=1cm]{example-image} & Tria& \\
\includegraphics[width=1cm]{example-image} & Obl & \\
\includegraphics[width=1cm]{example-image} & Sq & \\
\includegraphics[width=1cm]{example-image} & Rec &
\end{tabular}
\\ \midrule
2 &
\begin{tabular}{@{}m{1cm}m{2cm}m{2cm}@{}}
\includegraphics[width=1cm]{example-image} & SqSnSq & \\
\includegraphics[width=1cm]{example-image} & TrHex &
\end{tabular}
\\ \midrule
3 &
\begin{tabular}{@{}m{1cm}m{2cm}m{2cm}@{}}
\includegraphics[width=1cm]{example-image} & TrKag & \\
\includegraphics[width=1cm]{example-image} & RecShSq&
\end{tabular}
\\ \bottomrule
\end{tabular}
\end{table}
\end{document}
答案2
我不知道这是否是最好的解决方案,但您可以使用命令的vpos
和可选参数,如下所示vmove
multirow
大致:
\documentclass{article}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{multirow}
\usepackage{booktabs}
\usepackage{array}
\begin{document}
\begin{table}[]
\centering
\caption{My caption}
\label{my-label}
\begin{tabular}{c|m{1.5cm}m{2cm}l}
MR & GS & Typ & Sym \\ \hline
\multirow[c]{4}{*}[-1cm]{1} & \includegraphics[width=1cm, height=1cm]{imma}& Tria&\\
& \includegraphics[width=1cm, height=1cm]{imma} & Obl& \\
& \includegraphics[width=1cm, height=1cm]{imma} & Sq & \\ & \includegraphics[width=1cm, height=1cm]{imma} & Rec & \\ \hline
\multirow[c]{2}{*}[-0.4cm]{2} & \includegraphics[width=1cm, height=1cm]{imma} & SqSnSq & \\
& \includegraphics[width=1cm, height=1cm]{imma} & TrHex & \\ \hline
\multirow[c]{2}{*}[-0.4cm]{3} & \includegraphics[width=1cm, height=1cm]{imma} & TrKag & \\
& \includegraphics[width=1cm, height=1cm]{imma} & RecShSq& \\
\hline
\end{tabular}
\end{table}
\end{document}
产量:
基本上,您要使用的语法是\multirow[vpos]{x}{*}[-y]{T}
:
位置是
b
(底部)、c
(中心) 或t
顶部X是要跨越的列数
是是个垂直调整插入。我在它前面加了一个减号,因为你必须将东西往下移。
电视是多行的文本。
还请标记graphics
已被取代,graphicx
因此不再需要
答案3
\multirow
在应该使用的假设下,Moriambar 的解决方案是好的。
这是一个不同的解决方案,假设空单元格表示值的重复。
\documentclass{article}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{booktabs}
\usepackage[export]{adjustbox}
\begin{document}
\begin{table}[htp]
\centering
\caption{My caption}
\label{my-label}
\begin{tabular}{ccll}
\toprule
MR & GS & Typ & Sym \\
\midrule
1 & \includegraphics[width=1cm,height=1cm,valign=c]{example-image} & Tria & \\
\addlinespace[2pt]
& \includegraphics[width=1cm,height=1cm,valign=c]{example-image} & Obl & \\
\addlinespace[2pt]
& \includegraphics[width=1cm,height=1cm,valign=c]{example-image} & Sq & \\
\addlinespace[2pt]
& \includegraphics[width=1cm,height=1cm,valign=c]{example-image} & Rec & \\
\midrule
2 & \includegraphics[width=1cm,height=1cm,valign=c]{example-image} & SqSnSq & \\
\addlinespace[2pt]
& \includegraphics[width=1cm,height=1cm,valign=c]{example-image} & TrHex & \\
\midrule
3 & \includegraphics[width=1cm,height=1cm,valign=c]{example-image} & TrKag & \\
\addlinespace[2pt]
& \includegraphics[width=1cm,height=1cm,valign=c]{example-image} & RecShSq & \\
\bottomrule
\end{tabular}
\end{table}
\end{document}