
の使用に関していくつか問題があります\multicolumn
。下のスクリーンショットでわかるように、「Classical」と「Squared」という単語は列の中央に正しく配置されています。ただし、「Exponential」という単語は中央揃えになっていません。
コードは次のとおりです:
\begin{table}[]
\setlength{\tabcolsep}{12pt}
\centering
\begin{tabular}{l c c c c c c}
\hline\hline
\\\\[-4.3\medskipamount]
& \multicolumn{2}{c}{Classic} & \multicolumn{2}{c}{Squared} & \multicolumn{2}{c}{Exponential} \\
\textit{a} & 70 & 30 & 70 & 30 & 70 & 30 \\ [0.5ex]
\hline
\\\\[-3.9\medskipamount]
S100 & 91 & 31 & 71 & 01 & 21 & 41 \\
S100 & 91 & 31 & 71 & 01 & 21 & 41 \\
S100 & 91 & 31 & 71 & 01 & 21 & 41 \\
[1ex] \hline
\end{tabular}
\end{table}
ソリューションでは、引き続き tabular パッケージを使用することを希望します。よろしくお願いします。
答え1
理由は、この単語が少し長すぎるからです。もちろん、 の値を増やすこともできます\tabcolsep
。別の解決策としては\makebox[0pt]
、 を使用します。これにより、単語が列間のスペースに対称的にわずかに重なることが可能になります。
それ以外では、太booktabs
さが可変の の罫線を使用し、罫線の周囲に垂直方向のパディングを追加することをお勧めします。これにより、間隔を調整して手動で調整する必要がなくなります。
\documentclass{article}
\usepackage{booktabs}
\begin{document}
\begin{table}[]
\setlength{\tabcolsep}{12pt}
\centering
\begin{tabular}{l c c c c c c}
\toprule\midrule
& \multicolumn{2}{c}{Classic} & \multicolumn{2}{c}{Squared} & \multicolumn{2}{c}{\makebox[0pt]{Exponential}} \\
\textit{a} & 70 & 30 & 70 & 30 & 70 & 30 \\ [0.5ex]
\midrule
\\\\[-3.9\medskipamount]
S100 & 91 & 31 & 71 & 01 & 21 & 41 \\
S100 & 91 & 31 & 71 & 01 & 21 & 41 \\
S100 & 91 & 31 & 71 & 01 & 21 & 41 \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
答え2
S
パッケージの列タイプを使用しsiunitx
、S
列の幅を決定して、\cmidrule
以下の複数列セルを追加します。
\documentclass[12pt,a4paper]{article}
\usepackage{booktabs}
\usepackage{siunitx}
\begin{document}
\begin{table}
\centering
\begin{tabular}{l *{6}{S[table-format=2,
table-column-width=2em]}
}
\toprule
& \multicolumn{2}{c}{Classic}
& \multicolumn{2}{c}{Squared}
& \multicolumn{2}{c}{Exponential} \\
\cmidrule{2-3}\cmidrule(lr){4-5}\cmidrule{6-7}
\textit{a} & 70 & 30 & 70 & 30 & 70 & 30 \\
\midrule
S100 & 91 & 31 & 71 & 01 & 11 & 41 \\
S100 & 91 & 31 & 71 & 01 & 21 & 41 \\
S100 & 91 & 31 & 71 & 01 & 21 & 41 \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
答え3
使用する場合の問題\makebox[0pt]{}
は、Bernard が言ったように、長いヘッダーが列間のスペースと重なり、非常に見苦しいものになる可能性があることです。これを回避するには、2 つの数値列の幅の合計が、少なくとも長いヘッダーの幅と同じである必要があります。これは、C
次のように正確に計算して、新しい列タイプで定義できます。
\documentclass[12pt,a4paper]{article}
\usepackage{booktabs, array}
\begin{document}
\begin{table}
\setlength{\tabcolsep}{12pt}
\newlength\wexp
\settowidth{\wexp}{Exponential}
\newcolumntype{C}{>{\centering\arraybackslash}p{\dimexpr.5\wexp-\tabcolsep}}
\centering
\begin{tabular}{l c c c c C C}
\toprule
& \multicolumn{2}{c}{Classic} & \multicolumn{2}{c}{Squared} & \multicolumn{2}{c}{Exponential} \\
\textit{a} & 70 & 30 & 70 & 30 & 70 & 30 \\ \midrule
S100 & 91 & 31 & 71 & 01 & 11 & 41 \\
S100 & 91 & 31 & 71 & 01 & 21 & 41 \\
S100 & 91 & 31 & 71 & 01 & 21 & 41 \\ \bottomrule
\end{tabular}
\end{table}
\end{document}
答え4
私ならこう使います:
w{<align>}{<wd>}
すべての列の幅を固定する新しい列\setlength{\tabcolsep}{0.5em}
(1em
列間にスペースを設ける)- トリミング
cmidrule
- サイドベアリングなし(
@{}
) - 見出しのフォントを1段階小さくする
booktab
-ルールとaddlinespace[<wd>]
そしてMWE:
\documentclass{article}
\usepackage{booktabs, array, caption}
\begin{document}
\begin{table}[ht]
\caption{A table with figures\label{tab:atable}}
\setlength{\tabcolsep}{0.5em}
\centering
\begin{tabular}{@{}w{l}{4em}*{6}{w{c}{2em}}@{}}
\toprule
& \multicolumn{2}{c}{\small Classic} & \multicolumn{2}{c}{\small Squared} & \multicolumn{2}{c@{}}{\makebox[0pt]{\small Exponential}} \\\cmidrule(l{0.75em}r{0.75em}){2-3}\cmidrule(l{0.75em}r{0.75em}){4-5}\cmidrule(l{0.65em}){6-7}
\textit{a} & 70 & 30 & 70 & 30 & 70 & 30 \\
\midrule\addlinespace[1ex]
S100 & 91 & 31 & 71 & 01 & 21 & 41 \\
S100 & 91 & 31 & 71 & 01 & 21 & 41 \\
S100 & 91 & 31 & 71 & 01 & 21 & 41 \\
\bottomrule
\end{tabular}
\end{table}
\end{document}