Estoy usando tabularray
para crear una tabla con varios colspans y rowspans. La tabla tiene width = \linewidth
y colspec = {|X[1]|X[1]|X[2]|}
, pero excede el ancho de línea y X
no se obedecen las solicitudes de ancho de columna:
¿Cómo puedo hacer que la tabla se ciña al ancho de línea y respete los anchos de columna que he dado?
Ejemplo de trabajo mínimo:
\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}
Respuesta1
No mezcles la sintaxis de tablas clásicas con tabularray
las de unos: en su lugar \newline
deberías usar \\
.
Editar:Obtendrá un mejor espaciado del texto de las celdas si cambia `colspec˙ a:
colspec = {X[0.9, l,h] X[1.1, l,h] X[2,l,h]},
Teniendo en cuenta esto en la versión anterior de MWE, se obtiene
El MWE corregido es:
\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}
Respuesta2
Úselo \\
en lugar de \newline
(y ajuste {}
el contenido de la celda relevante) y el problema desaparecerá. Realmente no sé por qué \newline
no funciona aquí (de hecho, solo falla en la primera celda de la última línea). De todos modos, usar \\
es la forma en que el manual del paquete le indica que inserte saltos de línea después de todo:
\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}