我在\multirow
与\multicolumn
:
头部1.1应垂直居中。
头部1.2应该是垂直和水平居中的
是否有\multirow
和\multicolumn
的替代解决方案可以为LaTeX表创建更复杂的标头,还是可以修复我的问题?
\documentclass{article}
\usepackage{multirow}
\usepackage[utf8]{inputenc}
\usepackage[a4paper,margin=1in]{geometry}
\usepackage{array}
\newcolumntype{C}[1]{>{\centering\arraybackslash\hspace{0pt}}p{#1}}
\begin{document}
\begin{table}[ht]
\centering
\begin{tabular}{|r|r|r|r|}
\multicolumn{1}{|C{2cm}}{\multirow{3}{*}{head 1.1}} &
\multicolumn{2}{|C{2cm}}{\multirow{2}{*}{head 1.2}} &
\multicolumn{1}{|C{2cm}}{head 1.3 which is longer than expected} \\ \hline
& & & \multicolumn{1}{|C{2cm}}{head 2.3} \\
& \multicolumn{1}{|C{2cm}}{head 2.2.1} &
\multicolumn{1}{|C{2cm}}{head 2.2.2} &
\multicolumn{1}{|C{2cm}}{head 3.3}
\end{tabular}
\end{table}
\end{document}
答案 0 :(得分:1)
我建议使用tabular
堆叠您的多级标题/单元格,它会相对于其他单元格自然地垂直居中。使用makecell
:
tabular
堆叠
\documentclass{article}
\usepackage{makecell}
\begin{document}
\begin{tabular}{|r|r|r|r|}
head 1.1 &
\multicolumn{2}{c|}{head 1.2} &
\makecell{head 1.3 \\ which is \\ longer than \\ expected} \\
\hline
& head 2.2.1 & head 2.2.2 & \makecell{head 2.3 \\ head 3.3}
\end{tabular}
\end{document}
将单元格与[t]
op或[b]
ottom对齐也存在其他选项。