Establecer el ancho de la tabla exactamente al ancho de línea

Establecer el ancho de la tabla exactamente al ancho de línea

Estoy intentando crear una tabla con exactamente el mismo ancho que el texto circundante.

Esperaría que el comando \resizebox{\linewidth}{!}{..table..}hiciera el trabajo. Sin embargo, el ancho de las mesas sigue siendo demasiado pequeño.

ingrese la descripción de la imagen aquí

\documentclass{scrartcl} 
\usepackage{graphicx}
\usepackage[table]{xcolor}
\setlength{\parindent}{0pt}

\usepackage[
  top=0.600cm, 
  bottom=0.600cm,
  left=0.600cm, 
  right=0.600cm]
  {geometry}


\begin{document}
bla blub blaaa bla blub blaaabla blub blaaa bla blub blaaa bla blub blaaa bla blub blaaaa
bla blub blaaa bla blub blaaabla blub blaaa bla blub blaaa bla blub blaaa bla blub blaaaa
bla blub blaaa bla blub blaaabla blub blaaa bla blub blaaa bla blub blaaa bla blub blaaaa
bla blub blaaa bla blub blaaabla blub blaaa bla blub blaaa bla blub blaaa bla blub


\resizebox{\linewidth}{!}{
\begin{tabular}{|l|l|l|l|}
  \hline
  test entry & test entry & test entry & test entry \\
  test entry & test entry & test entry & test entry \\
  test entry & test entry & test entry & test entry \\
  \hline
\end{tabular}
}

\end{document}

Respuesta1

Creo que tienes dos buenas opciones y una (probablemente) terrible:

  • Utilice un tabular*entorno,

  • Utilice un tabularxentorno (o su primo cercano tabulary)

  • Utilice el entorno básico tabulary amplíelo (o reduzca) usando \resizebox.

Los resultados son los siguientes (la primera línea horizontal está ahí solo para ilustrar el ancho del bloque de texto; lacuerposde las cuatro tablas son idénticas, es decir, se diferencian "sólo" en su diseño):

ingrese la descripción de la imagen aquí

¿Puedes decir por qué considero que el método que utiliza \resizeboxes nada menos que terrible?

\documentclass{scrartcl} 
\usepackage{graphicx} % for '\resizebox` macro
\usepackage{tabularx} % for 'tabularx' environment
\setlength{\parindent}{0pt}
\usepackage[margin=0.6cm]{geometry}
\newcommand\TestTable{% define body of test table
  \hline
  test entry & test entry & test entry & test entry \\
  test entry & test entry & test entry & test entry \\
  test entry & test entry & test entry & test entry \\
  \hline}
\begin{document}
\hrule

\subsubsection*{Unscaled}

\begin{tabular}{llll}
\TestTable
\end{tabular}

\subsubsection*{Using \texttt{tabular*}}

\begin{tabular*}{\textwidth}{l@{\extracolsep{\fill}}lll}
\TestTable
\end{tabular*}

\subsubsection*{Using \texttt{tabularx}}

\begin{tabularx}{\textwidth}{XXXX}
\TestTable
\end{tabularx}

\subsubsection*{Scaled with \texttt{\textbackslash resizebox}}

\resizebox{\linewidth}{!}{%
\begin{tabular}{llll}
\TestTable
\end{tabular}}

\end{document}

información relacionada