# Resizing a table by textheight

Say, I have a table which doesn't fit on one page. Say, I don't want to use any special table types or so but want to solve the problem by using the \resizebox-command and keep my ratio.

If by using \resizebox{\texwidth}{!}{...} the table fits, then my problem is solved. But if the table is still too long, my instinct would be to use \resizebox{!}{\textheight}{...} instead. Allowing some space for my caption I would have to adjust the height to about 0.9\textheight to be sure for a single line caption. But in my example I have ta adjust to approx. 0.48\textheight to get rid of all warnings and fit the table on the page. This seems very odd to me. What am I missing?

\documentclass{article}
\usepackage{graphicx}

\begin{document}
\begin{table}[htbp]
\centering
%   \resizebox{\textwidth}{!}{
\resizebox{!}{0.48\textheight}{
\begin{tabular}{|lll|}\hline
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\ \hline
\end{tabular}}
\caption{test}
\end{table}
\end{document}

-

You are running into the common problem of confusing the height and the totalheight of things in TeX. For some reason which also surprised me the baseline of the table is the the middle of the table, so that the lower half is part of the depth of the resulting TeX box. The \resizebox scales the box height, not the totalheight (height+depth) to the given value. To scale the totalheight use the * version. You can also use \dimexpr (see also Doing maths with distance values in LaTeX source code) or the calc package to subtract e.g. two lines from the height:

\resizebox*{!}{\dimexpr\textheight-2\baselineskip\relax}{%


Also note that placing a large table in a macro argument is very inefficient and doesn't allow the usage of \verb etc. in the table. You can use the \adjustbox macro or adjustbox environment from the relative new adjustbox package (written by me) to scale any content instead. Both read the content as box not as argument and avoid the mentioned drawbacks:

\usepackage{adjustbox}
% [...]


The adjustbox environment and macro accepts all options of the \includegraphics macro. This includes height and totalheight.
Note that adjustbox uses pgfmath to parse the given dimensions, so you can use all math supported by this package. However do not use \dimexpr directly because it isn't supported by pgfmath.
I fixed the previously mentioned issue with identical output for height and totalheight now and uploaded the correct version as 2011/03/20 v0.3 to CTAN. However, simply using totalheight as shown now works also with the previous version. – Martin Scharrer Mar 20 '11 at 20:55
The baseline of the tabular is in the middle as the default position argument is [c], if you use t or b then the baseline is the baseline of the top or bottom row (or rule). – David Carlisle Oct 24 '13 at 14:50