这听起来很奇怪,但我需要单元格拆分。我如何才能垂直和水平居中此 MWE 中的内容:
\begin{table*}[htbp]
\centering
\caption{MWE}
\begin{tabular}{l|l|l|l|l}
\hline\noalign{\smallskip}
& & Does this really work & this & way? \\ \hline
\noalign{\smallskip}\hline\noalign{\smallskip}
Testing centering &
\begin{tabular}{c} This \\ \hline is a \\ \hline test \end{tabular} &
\begin{tabular}{c} 1 \\ \hline 2 \\ \hline 3 \end{tabular} &
\begin{tabular}{c} oneoneone \\ \hline twotwotwo \\ \hline threethreethree \end{tabular} &
\begin{tabular}{c} 4 \\ \hline 5 \\ \hline 6 \end{tabular} \\ \hline
\noalign{\smallskip}\hline
\end{tabular}
\end{table*}
如果你看一下,你会发现 1|2|3 以及其他单元格内容没有居中。我也尝试过\centering
围绕\begin{center}
单元格,但没有成功。我遗漏了什么?
谢谢!
答案1
关于单元格内容的居中,您已在上面的评论中找到解决方案。因此,我仅建议使用包\makecell
中的宏\makecell
而不是嵌套表:
\documentclass[a4paper,11pt]{scrbook}
\usepackage[utf8]{inputenc}
\usepackage{booktabs,makecell}
\begin{document}
\begin{table*}[htb]
\centering
\caption{MWE}
\begin{tabular}{*{5}{c}}
\toprule
& & Does this really work & this & way? \\
\midrule
Testing centering &
\makecell{This \\
is a \\
test}
& \makecell{1 \\
2 \\
3}
& \makecell{oneoneone \\
twotwotwo \\
threethreethree}
& \makecell{4 \\
5 \\
6} \\
\bottomrule
\end{tabular}
\end{table*}
\end{document}
我还\hline
用包中的规则替换了您的构造booktabs
并删除了垂直线。Meany 认为这样的表格设计很“专业”: