Tabularray 超出線寬

Tabularray 超出線寬

我用來tabularray創建一個具有各種列跨度和行跨度的表。表格有width = \linewidthcolspec = {|X[1]|X[1]|X[2]|},但超出了線寬,並且X不遵守列寬要求:

桌子

如何使表格堅持線寬,並尊重我給的列寬?

最小工作範例:

\documentclass{article}

\usepackage{multicol}
\usepackage{graphicx}
\usepackage{makecell}
\usepackage{tabularray}
\usepackage{pgffor, etoolbox}

% headers and footers
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{} % clear existing header/footer entries
\fancyhead[C]{\footnotesize test}

\begin{document}

\noindent
\begin{tblr}{
    width = \linewidth,
    colspec = {|X[1]|X[1]|X[2]|}
}
%\begin{tblr}{|p{0.2\linewidth}|p{0.2\linewidth}|p{0.4\linewidth}|}
    \hline
    \SetCell[c=3]{c} \textbf{DOCUMENTATION INFORMATION PAGE} & &
    \\
    \hline
    \textbf{1. DATE} \newline date & \textbf{2. DOCUMENT TYPE} \newline document type & \textbf{3. DOCUMENT NUMBER / REV} \newline document number \space document version
    \\
    \hline
    \SetCell[c=2]{l} \textbf{4. Title \newline title } & & \textbf{5. PROJECT CODE} \newline project code
    \\
    \hline
    \SetCell[c=2]{l} \textbf{6. AUTHOR} \newline author & & \textbf{7. CUSTOMER} \newline customer
    \\
    \hline
    \SetCell[c=2,r=2]{l} {
        \textbf{8. CONTACT ADDRESS} \\
        Lorem \\
        Ipsum \\
        Dolor \\
        Sit \\
        Amet
    }
    &
    &
    \textbf{9. CONTACT PHONE} \newline telephone number \vspace{0.4em}
    \\
    \hline
    &
    &
    \textbf{10. CONTACT EMAIL} \newline author email
    \\
    \hline
    \SetCell[c=2]{l} \textbf{11. TELEPHONE NUMBER} \newline telephone number
    &
    &
    \textbf{12. NAME OF RESPONSIBLE PERSON} \newline author
    \\
    \hline
\end{tblr}

\end{document}

答案1

不要將經典表中的語法與tabularray其他表混合使用:相反,\newline您應該使用\\.

編輯:如果您將“colspec”變更為:

colspec = {X[0.9, l,h] X[1.1, l,h] X[2,l,h]},

在先前的 MWE 版本中考慮到這一點給出

在此輸入影像描述

修正後的 MWE 為:

\documentclass{article}
%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\usepackage{lipsum}% For dummy text. Don't use in a real document

\usepackage{multicol}
\usepackage{graphicx}
\usepackage{makecell}
\usepackage{tabularray}
\usepackage{pgffor, etoolbox}

% headers and footers
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{} % clear existing header/footer entries
\fancyhead[C]{\footnotesize test}

\begin{document}

\noindent%
\begin{tblr}{hlines, vlines,
             colspec = {X[0.9, l,h] X[1.1, l,h] X[2,l,h]},
             row{1}  = {font=\bfseries},
             cell{3-Z}{1} = {c=2}{},
             vspan=even
             }
\SetCell[c=3]{c}    DOCUMENTATION INFORMATION PAGE
    &   &   \\
{\textbf{1. DATE}\\ date} 
    &   {\textbf{2. DOCUMENT TYPE}\\ document type}
        &   {\textbf{3. DOCUMENT NUMBER/REV}\\ document number\\ document version}   \\
{\textbf{4. Title\\ title}} 
    &   &   {\textbf{5. PROJECT CODE}\\ project code}                                 \\
{\textbf{6. AUTHOR}\\ author}  
    &   &   {\textbf{7. CUSTOMER}\\ customer}                                       \\
\SetCell[c=2, r=2]{l}    {\textbf{8. CONTACT ADDRESS}                                    \\
                    Lorem \\
                    Ipsum \\
                    Dolor \\
                    Sit \\
                    Amet}
    &   &   {\textbf{9. CONTACT PHONE}\\ telephone number}                          \\
    &   &   {\textbf{10. CONTACT EMAIL}\\ author email}                             \\
{\textbf{11. TELEPHONE NUMBER}\\ telephone number}
    &   & {\textbf{12. NAME OF RESPONSIBLE PERSON}\\ author}                        \\
\end{tblr}
\end{document}

答案2

使用\\代替\newline(並{}環繞相關的單元格內容),問題就消失了。我真的不知道為什麼\newline在這裡不起作用(事實上它只在最後一行的第一個單元格中出現錯誤)。無論如何,使用\\是軟體包手冊告訴您插入換行符的方式:

\documentclass{article}
\usepackage{tabularray}

% headers and footers
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{} % clear existing header/footer entries
\fancyhead[C]{\footnotesize test}

\begin{document}

\noindent
\begin{tblr}{
    width = \linewidth,
    colspec = {|X[1]|X[1]|X[2]|}
}
%\begin{tblr}{|p{0.2\linewidth}|p{0.2\linewidth}|p{0.4\linewidth}|}
    \hline
    \SetCell[c=3]{c} \textbf{DOCUMENTATION INFORMATION PAGE} & &
    \\
    \hline
    { \textbf{1. DATE} \\ date } & 
    { \textbf{2. DOCUMENT TYPE} \\ document type } & 
    { \textbf{3. DOCUMENT NUMBER / REV} \\ document number \space document version }
    \\
    \hline
    \SetCell[c=2]{l} 
    { \textbf{4. Title} \\ title } & & 
    { \textbf{5. PROJECT CODE} \\ project code }
    \\
    \hline
    \SetCell[c=2]{l} 
    { \textbf{6. AUTHOR} \\ author } & & 
    { \textbf{7. CUSTOMER} \\ customer }
    \\
    \hline
    \SetCell[c=2,r=2]{l} 
    {
        \textbf{8. CONTACT ADDRESS} \\
        Lorem \\
        Ipsum \\
        Dolor \\
        Sit \\
        Amet
    }
    &
    &
    { \textbf{9. CONTACT PHONE} \\ telephone number } \vspace{0.4em} 
    \\
    \hline
    &
    &
    { \textbf{10. CONTACT EMAIL} \\ author email }
    \\
    \hline
    \SetCell[c=2]{l} 
    { \textbf{11. TELEPHONE NUMBER} \\ telephone number }
    &
    &
    { \textbf{12. NAME OF RESPONSIBLE PERSON} \\ author }
    \\
    \hline
\end{tblr}

\end{document}

在此輸入影像描述

相關內容