
4 行、3 列、列 2-3 に部分的な水平線がある表が必要です。次の操作を試しました:
\documentclass{article}
\begin{document}
\begin{table}
{
\begin{center}
\begin{tabular}{|c|c|c|}
\hline
Col 1 & \multicolumn{2}{|c|}{Col 2-3 Heading}\\
\cline{2-3} & Col 2 & Col 3\\
\hline
- & - & -\\
\hline
- & - & - \\
\hline
- & - & - \\
\hline
\end{tabular}
\end{center}
}
\end{table}
\end{document}
その結果、次のようになりました。
列 2 と 3 の幅が等しくないことに注意してください。どうすれば修正できますか?
答え1
を使用して生成されたスパン セルの内容の幅が\multicolumn
個々のセルの内容の幅よりも大きい場合、経験済みであり、次の例でさらに明確にわかるように、最後のスパン列に余分なスペースが追加されます。
\documentclass{article}
\begin{document}
\noindent\begin{tabular}{|c|c|c|c|}
\hline
A & \multicolumn{3}{c|}{Some text just for the example} \\
\hline
B & C & D & E \\
\hline
\end{tabular}
\end{document}
2 つのオプション: 中央揃えの列に変更できますp{...}
(2 つのオプションは、パッケージの有無にかかわらず、同じアプローチを示していますtabularx
)。
\documentclass{article}
\usepackage{tabularx}
\newcolumntype{C}{>{\centering\arraybackslash}p{1.5cm}}
\newcolumntype{Y}{>{\centering\arraybackslash}X}
\begin{document}
\begin{table}
\centering
\begin{tabular}{|c|c|c|}
\hline
Col 1 & \multicolumn{2}{c|}{Col 2-3 Heading}\\
\cline{2-3} & Col 2 & Col 3\\
\hline
- & - & -\\
\hline
- & - & - \\
\hline
- & - & - \\
\hline
\end{tabular}
\end{table}
\begin{table}
\centering
\begin{tabular}{|C|C|C|}
\hline
Col 1 & \multicolumn{2}{c|}{Col 2-3 Heading}\\
\cline{2-3} & Col 2 & Col 3\\
\hline
- & - & -\\
\hline
- & - & - \\
\hline
- & - & - \\
\hline
\end{tabular}
\end{table}
\begin{table}
\centering
\begin{tabularx}{6cm}{|Y|Y|Y|}
\hline
Col 1 & \multicolumn{2}{c|}{Col 2-3 Heading}\\
\cline{2-3} & Col 2 & Col 3\\
\hline
- & - & -\\
\hline
- & - & - \\
\hline
- & - & - \\
\hline
\end{tabularx}
\end{table}
\end{document}
質問とは関係ありませんが、内部ではフロートを使用する方が適切であり\centering
、center
環境は使用しないでください。後者は余分な垂直スペースを追加しますが、ほとんどの場合、これは望ましくありません。