[Tex/LaTex] Setting table-width exactly to linewidth

scalingtableswidth

I'm trying to create a table with exactly the same width as the surronding text.

I would expect that the command \resizebox{\linewidth}{!}{..table..} should do the job. However, the tables width is still too small.

enter image description here

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

Best Answer

I think you have two good choices and a (likely) dreadful choice:

  • Use a tabular* environment,

  • Use a tabularx environment (or its close cousin, tabulary)

  • Use the basic tabular environment and scale it up (or down) using \resizebox.

The results are as follows (the first horizontal line is there just to illustrate the width of the text block; the bodies of the four tables are identical, i.e., they differ "only" in their layouts):

enter image description here

Can you tell why I consider the method that uses \resizebox to be nothing short of dreadful?

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