Estou usando tabularray
para criar uma tabela com vários colspans e rowspans. A tabela possui width = \linewidth
and colspec = {|X[1]|X[1]|X[2]|}
, mas excede a largura da linha e as X
solicitações de largura da coluna não são obedecidas:
Como posso fazer com que a tabela siga a largura da linha e respeite as larguras das colunas que forneci?
Exemplo mínimo de trabalho:
\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}
Responder1
Não misture sintaxe de tabelas clássicas com tabularray
outras: em vez disso, \newline
você deve usar \\
.
Editar:Você obterá melhor espaçamento do texto das células se alterar `colspec˙ para:
colspec = {X[0.9, l,h] X[1.1, l,h] X[2,l,h]},
Considerando isso na versão anterior do MWE dá
MWE corrigido é:
\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}
Responder2
Use \\
em vez de \newline
(e envolva {}
o conteúdo relevante da célula) e o problema desaparecerá. Eu realmente não sei por que \newline
não funciona aqui (na verdade, só buga na primeira célula da última linha). De qualquer forma, usar \\
é a forma como o manual do pacote diz para você inserir quebras de linha:
\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}