
을(를) 사용하는 데 몇 가지 문제가 있습니다 \multicolumn
. 아래 스크린샷에서 볼 수 있듯이 'Classical'과 'Squared'라는 단어가 열 중앙에 올바르게 정렬되어 있습니다. 그러나 '지수'라는 단어는 중앙에 제대로 배치되지 않았습니다.
코드는 다음과 같습니다
\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}
솔루션에서 테이블 형식 패키지를 계속 사용하고 싶습니다. 미리 감사드립니다!
답변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가 말했듯이 긴 헤더가 열 간 간격과 겹쳐서 꽤 보기 흉해 보일 수 있다는 것입니다. 이를 방지하려면 두 숫자 열의 너비의 합이 최소한 긴 머리글의 너비와 같아야 합니다. 이는 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
- 측면 베어링 없음(
@{}
) - 제목에 한 등급 더 작은 글꼴
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}