乳胶结合多管和多管

时间:2017-09-28 15:51:54

标签: latex multirow

我在\multirow\multicolumn

合并时发现了一些奇怪的行为

pdf output of code below

  • 头部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}

1 个答案:

答案 0 :(得分:1)

我建议使用tabular堆叠您的多级标题/单元格,它会相对于其他单元格自然地垂直居中。使用makecell

可以轻松实现tabular堆叠

enter image description here

\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对齐也存在其他选项。