BOOKTABS 테이블의 테이블 셀에서 줄 바꿈

BOOKTABS 테이블의 테이블 셀에서 줄 바꿈

간단히 말해서:

패키지를 사용할 때 왼쪽 정렬된 표 셀에 자동 줄 바꿈을 어떻게 제공할 수 있나요 bookstabs?

내 문제의 세부사항:

저는 ACM 잡지에 (희망적으로) 출판될 과학 논문을 쓰고 있습니다. 문서 클래스에는 다음 패키지가 포함됩니다 booktabs.https://ctan.org/pkg/booktabs스타일 가이드에서는 다른 테이블 스타일을 사용할 수 없습니다.

그 전에는 초안 문서에서 패키지를 사용하여 다음 테이블을 만들었습니다 tabularray.

\documentclass{article}
\usepackage{tabularray} % <-- line 2
\begin{document}
\begin{table}
    \begin{tblr}{X[l]X[l]rrr} % <-- line 5
        \hline
        Authors/Editors & Title & Pages & Year & Ref. \\
        \hline
        David Salomon and Giovanni Motta & 
        Handbook of Data Compression & 1,370 & 2010 & [1] \\
        Colt McAnlis and Aleks Haecky & 
        Understanding Compression: Data Compression 
        for Modern Developers & 241 & 2016 & [2] \\
        \hline
    \end{tblr} % <-- line 15
\end{table}
\end{document}

다음 테이블이 생성됩니다.

tabularray 패키지로 만든 테이블
그림 1: 패키지로 만든 테이블tabularray

그런 다음 를 사용하는 ACM 템플릿에서 시도했지만 booktabs실패했습니다. 다음은 이 패키지를 사용하는 예제 코드입니다. 2, 5, 15행만 다릅니다(주석으로 표시).

\documentclass{article}
\usepackage{booktabs} % <-- line 2
\begin{document}
\begin{table}
    \begin{tabular}{llrrr} % <-- line 5
        \hline
        Authors/Editors & Title & Pages & Year & Ref. \\
        \hline
        David Salomon and Giovanni Motta & 
        Handbook of Data Compression & 1,370 & 2010 & [1] \\
        Colt McAnlis and Aleks Haecky & 
        Understanding Compression: Data Compression 
        for Modern Developers & 241 & 2016 & [2] \\
        \hline
    \end{tabular} % <-- line 15
\end{table}
\end{document}

결과는 다음과 같습니다.

패키지 북탭으로 만든 테이블
그림 2: 패키지로 만든 테이블 booktabsllrrr

단어 줄 바꿈이 없고 표가 너무 넓어 페이지에 맞지 않습니다. 오른쪽에서 잘립니다.

I를 사용하면 매개변수 (5행)를 tabularray사용하여 왼쪽 정렬된 표 셀에서 자동 줄 바꿈을 지정할 수 있습니다 . X[l]이 작업을 시도하면 booktabs오류 메시지("LaTeX 오류: 배열 인수에 잘못된 문자가 있습니다.")가 표시되고 단어 줄 바꿈 및 가운데 맞춤 텍스트가 없는 테이블 셀이 표시됩니다.

북탭을 사용한 두 번째 버전
그림 3: 패키지로 만든 테이블 booktabsX[l]X[l]rrr

X[l]으로 교체하면 l그림 2에서 볼 수 있는 내용을 얻을 수 있습니다(오류 없음).

~에https://ctan.org/pkg/booktabs18페이지 길이 의 패키지 문서이지만 booktabs열 너비, 줄 바꿈 또는 유사한 주제에 대한 언급은 어디에도 없습니다. 사실 18페이지 모두 수평선의 두께라는 단 하나의 주제만을 다루고 있는데, 이는 별로 도움이 되지 않습니다.

내 질문은 다음과 같습니다.

첫 번째 예에서처럼 단어 줄바꿈이 포함된 테이블을 만들려면 어떻게 해야 합니까? 단, 패키지의 경우에는 어떻게 해야 합니까 bookstabs?

답변1

문제는 사용하는 것이 booktabs아니라 열 설정 방법을 지정하지 않았다는 것입니다. p{width}여러 텍스트 줄이 있는 열에 사용합니다 .

% booktabsprob.tex  SE 640799

\documentclass{article}
\usepackage{booktabs} % <-- line 2
\begin{document}
\begin{table}
%    \begin{tabular}{llrrr} % <-- line 5
    \begin{tabular}{lp{4cm}rrr} % <-- line 5
        \hline
        Authors/Editors & Title & Pages & Year & Ref. \\
        \hline
        David Salomon and Giovanni Motta & 
        Handbook of Data Compression & 1,370 & 2010 & [1] \\
        Colt McAnlis and Aleks Haecky & 
        Understanding Compression: Data Compression 
        for Modern Developers & 241 & 2016 & [2] \\
        \hline
    \end{tabular} % <-- line 15
\end{table}
\end{document}

여기에 이미지 설명을 입력하세요

답변2

With tabularray및 해당 라이브러리 booktabs( booktabs패키지도 로드함):

\documentclass{article}
\usepackage{tabularray}
\UseTblrLibrary{booktabs} % <---

\begin{document}
\begin{table}
    \begin{tblr}{colsep = 4pt,
                 colspec = {@{} X[0.8,l]X[1.2,l]rrr @{}}
                 }
    \toprule
Authors/Editors & Title & Pages & Year & Ref.   \\
    \midrule
David Salomon and Giovanni Motta 
                & Handbook of Data Compression 
                        & 1,370 & 2010 & [1]    \\
Colt McAnlis and Aleks Haecky 
                & Understanding Compression: Data Compression
        for Modern Developers 
                        &   241 & 2016 & [2]    \\
    \bottomrule
    \end{tblr}
\end{table}
\end{document}

여기에 이미지 설명을 입력하세요

답변3

다음을 사용하여 가능한 해결책은 다음과 같습니다 tabularx.

    \documentclass{article}
    \usepackage{tabularx}
    \usepackage{booktabs} % <-- line 2

    \begin{document}

    \begin{table}
        \begin{tabularx}{\textwidth}{XXrrr} % <-- line 5
            \toprule
            Authors/Editors & Title & Pages & Year & Ref. \\
            \midrule
            David Salomon and Giovanni Motta &
            Handbook of Data Compression & 1,370 & 2010 & [1] \\ \addlinespace
            Colt McAnlis and Aleks Haecky &
            Understanding Compression: Data Compression
            for Modern Developers & 241 & 2016 & [2] \\
            \bottomrule
        \end{tabularx} % <-- line 15
    \end{table}

    \end{document} 

여기에 이미지 설명을 입력하세요

답변4

당신은 물었습니다.

패키지를 사용할 때 왼쪽 정렬된 표 셀에 [줄 바꿈]을 어떻게 제공할 수 있나요 booktabs?

자동 줄 바꿈을 활성화하는 것은 패키지에서 제공하는 기능과 완전히 다릅니다 booktabs. 발견한 대로 l열 유형은 자동 줄 바꿈을 제공하지 않습니다. 패키지 를 로드하고 , 대신 tabularx시조 환경을 사용하고 , 환경 의 전체 너비를 로 설정 하고, 처음 두 열에 대해 패키지의 열 유형을 사용하는 것이 좋습니다 .tabularxtabulartabularx\textwidthX

tabularx@Bernard가 추구하는 기반 접근 방식 과 관련하여이 답변, 아래에서 추구하는 접근 방식은 (a) 테이블의 왼쪽 및 오른쪽 가장자리에 있는 공백 패딩을 제거하고, (b) 열 1과 2의 셀 내용을 완전히 정당화하지 않으며, (c) 대신 중앙 집합을 사용합니다. than은 열 3부터 5까지의 내용을 오른쪽 정렬하고, (d)는 패키지 S의 열 유형을 사용하여 siunitx(암시적) 소수 표시에서 열 3의 숫자를 정렬합니다.

여기에 이미지 설명을 입력하세요

\documentclass{article}
\usepackage{booktabs} 
\usepackage{tabularx,ragged2e}
\newcolumntype{L}{>{\RaggedRight}X}
\usepackage{siunitx} % for S column type
\begin{document}

\begin{table}
    \begin{tabularx}{\textwidth}{@{} 
          LL 
          S[table-format=4.0,group-separator={,},group-minimum-digits=4]
          cc @{}} 
        \toprule
        Authors/Editors & Title & {Pages} & Year & Ref. \\
        \midrule
        David Salomon and Giovanni Motta & 
        Handbook of Data Compression & 1370 & 2010 & [1] \\
        \addlinespace
        Colt McAnlis and Aleks Haecky & 
        Understanding Compression: Data Compression 
        for Modern Developers & 241 & 2016 & [2] \\
        \bottomrule
    \end{tabularx} 
\end{table}

\end{document}

관련 정보