테이블의 여러 열이 가운데에 있지 않음

테이블의 여러 열이 가운데에 있지 않음

을(를) 사용하는 데 몇 가지 문제가 있습니다 \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

나는 다음을 사용했을 것이다:

  1. w{<align>}{<wd>}모든 열의 너비를 고정하는 새 열
  2. \setlength{\tabcolsep}{0.5em}( 1em열 사이에 공간을 제공합니다)
  3. 트리밍됨cmidrule
  4. 측면 베어링 없음( @{})
  5. 제목에 한 등급 더 작은 글꼴
  6. 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}

관련 정보