1

I'm using tabularray to create a table with various colspans and rowspans. The table has width = \linewidth and colspec = {|X[1]|X[1]|X[2]|}, but it exceeds the linewidth, and the column width X requests are not obeyed:

table

How can I get the table to stick to the linewidth, and to respect the column widths I've given?

Minimum working example:

\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}

2 Answers 2

4

Don't mix syntax from classic tables with tabularray ones: instead \newline you should use \\.

Edit: Better spacin of cells' text you will get, if you will change `colspec˙ to:

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

Considering this in previous MWE version gives

enter image description here

Corrected MWE is:

\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
  • thanks! So you're wrapping all the cells in each row in {}? or is that a typo with missing } after {\textbf{1. DATE}\\ date ?
    – ACarter
    Commented Mar 16, 2023 at 10:48
  • @ACarter, ups, it is tipo, but in two columns, so they compensate each other and not throw errors. Now corrected.
    – Zarko
    Commented Mar 16, 2023 at 10:56
1

Use \\ instead of \newline (and wrap {} around the relevant cell contents) and the problem is gone. I don't really know why \newline does not work here (in fact it only bugs in the first cell of the last line). Anyways, using \\ is the way the package manual tells you to insert line breaks after all:

\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}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .