我需要创建一个多行表;只有第三列有两行:
\documentclass{article}
\usepackage{multirow}
\begin{document}
\begin{table}
\centering
\caption{Example LaTeX Table with \texttt{\textbackslash multirow}}
\label{tab:example_multirow}
\small % text size of table content
\centering % center the table
\begin{tabular}{lcr} % alignment of each column data
\toprule[\heavyrulewidth]\toprule[\heavyrulewidth]
\textbf{Security Level} & \textbf{Security Mode} & \textbf{Protection} \\
\midrule
\hline
0&\multirow{2}{*}{Common g text} & Column g2a \\
& Column g2b \\
\hline
\bottomrule[\heavyrulewidth]
\end{tabular}
\end{table}
\end{document}
答案1
您缺少一个&
。如果“Column g2b”应该位于第 3 列,则它前面需要 2 个列分隔符。现在,TeX 认为文本位于第二列。
此外,您可能还希望将零括在里面\multirow
,以便它也居中:
[...]
\multirow{2}{*}{0} & \multirow{2}{*}{Common g text} & Column g2a \\
& & Column g2b \\
[...]
答案2
也许您想要其中一种布局?这里的工具是包makeecell
。请注意,第二种解决方案不需要multirow
。另外,我简化了顶部和底部规则的代码:\heavyrulewidth
是默认的。
\documentclass{article}
\usepackage{array, multirow, makecell, caption, booktabs}
\setlength{\extrarowheight}{2pt}
\begin{document}
\begin{table}
\centering
\caption{Example LaTeX Table with \texttt{\textbackslash multirow}}
\label{tab:example_multirow}
\small % text size of table content
\centering % center the table
\begin{tabular}{lcr} % alignment of each column data
\toprule\toprule
\textbf{Security Level} & \textbf{Security Mode} & \textbf{Protection} \\
\midrule
\midrule
0&\multirowcell{2}{Common g tex\\ Column g2b} & Column g2a \\
& \\
\midrule
\bottomrule
\end{tabular}
\vskip 1cm
\begin{tabular}{lcr} %
\toprule\toprule
\textbf{Security Level} & \textbf{Security Mode} & \textbf{Protection} \\
\midrule
\midrule
0& \makecell{Common g tex\\ Column g2b} & Column g2a \\
\midrule
\bottomrule
\end{tabular}
\end{table}
\end{document}
编辑:
如果您需要第三列有两行,则可以使用\makecell
:
\begin{tabular}{lcr} %
\toprule\toprule
\textbf{Security Level} & \textbf{Security Mode} & \textbf{Protection} \\
\midrule
\midrule
0& \makecell{Common g tex\\ Column g2b} & \makecell[r]{Column g2a \\ Column geb} \\
\midrule
\bottomrule
\end{tabular}