[Tex/LaTex] Fitting tables into beamer

beamerheightscalingtables

I have some tables in my presentations that are rather big. I found out how to use \resizebox to fit them into my page. Unfortunately this only works for tables that are wide. For long tables, my method doesn't work. Here is my minimal example:

\documentclass{beamer}

\begin{document}

\begin{frame}{Well formulated title}
   \include{table}
\end{frame}

\end{document}

and the file table.tex is

\resizebox{\textwidth}{!}{
\begin{tabular}{rrrrrrrr}
111111 & 222222 & 3333333 & 44444444 & 55555555 & 66666666 & 77777777 & 88888888 \\
111111 & 222222 & 3333333 & 44444444 & 55555555 & 66666666 & 77777777 & 88888888 \\
111111 & 222222 & 3333333 & 44444444 & 55555555 & 66666666 & 77777777 & 88888888 \\
111111 & 222222 & 3333333 & 44444444 & 55555555 & 66666666 & 77777777 & 88888888 \\
111111 & 222222 & 3333333 & 44444444 & 55555555 & 66666666 & 77777777 & 88888888 \\
111111 & 222222 & 3333333 & 44444444 & 55555555 & 66666666 & 77777777 & 88888888 \\
111111 & 222222 & 3333333 & 44444444 & 55555555 & 66666666 & 77777777 & 88888888 \\
111111 & 222222 & 3333333 & 44444444 & 55555555 & 66666666 & 77777777 & 88888888 \\
111111 & 222222 & 3333333 & 44444444 & 55555555 & 66666666 & 77777777 & 88888888 \\
111111 & 222222 & 3333333 & 44444444 & 55555555 & 66666666 & 77777777 & 88888888 \\
111111 & 222222 & 3333333 & 44444444 & 55555555 & 66666666 & 77777777 & 88888888 \\
111111 & 222222 & 3333333 & 44444444 & 55555555 & 66666666 & 77777777 & 88888888 \\
111111 & 222222 & 3333333 & 44444444 & 55555555 & 66666666 & 77777777 & 88888888 \\
111111 & 222222 & 3333333 & 44444444 & 55555555 & 66666666 & 77777777 & 88888888 \\
111111 & 222222 & 3333333 & 44444444 & 55555555 & 66666666 & 77777777 & 88888888 \\
111111 & 222222 & 3333333 & 44444444 & 55555555 & 66666666 & 77777777 & 88888888 \\
111111 & 222222 & 3333333 & 44444444 & 55555555 & 66666666 & 77777777 & 88888888 \\
111111 & 222222 & 3333333 & 44444444 & 55555555 & 66666666 & 77777777 & 88888888 \\
111111 & 222222 & 3333333 & 44444444 & 55555555 & 66666666 & 77777777 & 88888888 \\
111111 & 222222 & 3333333 & 44444444 & 55555555 & 66666666 & 77777777 & 88888888 \\
111111 & 222222 & 3333333 & 44444444 & 55555555 & 66666666 & 77777777 & 88888888 \\
111111 & 222222 & 3333333 & 44444444 & 55555555 & 66666666 & 77777777 & 88888888 \\
111111 & 222222 & 3333333 & 44444444 & 55555555 & 66666666 & 77777777 & 88888888 \\
111111 & 222222 & 3333333 & 44444444 & 55555555 & 66666666 & 77777777 & 88888888 \\
111111 & 222222 & 3333333 & 44444444 & 55555555 & 66666666 & 77777777 & 88888888 \\
111111 & 222222 & 3333333 & 44444444 & 55555555 & 66666666 & 77777777 & 88888888 \\
111111 & 222222 & 3333333 & 44444444 & 55555555 & 66666666 & 77777777 & 88888888 \\
111111 & 222222 & 3333333 & 44444444 & 55555555 & 66666666 & 77777777 & 88888888
\end{tabular}
}

As one can see this table is now too long for the page. So I thought that I could try \resizebox{!}{\textheight} instead of \resizebox{\textwidth}{!} but unfortunately this does not come out as expected.

Is there a possibility to determine the maximal height of the hbox so that my table is as high as possible without producing an overfull hbox?

I know that I could just set some values myself that kinda fit but I want to have a possibility to do it automatically.

Best Answer

You need rather less that \textheight to allow room for the title. Also, it's probably easier to use adjustbox than \resizebox:

enter image description here

\documentclass{beamer}
\usepackage{adjustbox}
\begin{document}

\begin{frame}{Well formulated title}
\centering
\adjustbox{max height=\dimexpr\textheight-5.5cm\relax,
           max width=\textwidth}{
\begin{tabular}{rrrrrrrr}
111111 & 222222 & 3333333 & 44444444 & 55555555 & 66666666 & 77777777 & 88888888 \\
111111 & 222222 & 3333333 & 44444444 & 55555555 & 66666666 & 77777777 & 88888888 \\
111111 & 222222 & 3333333 & 44444444 & 55555555 & 66666666 & 77777777 & 88888888 \\
111111 & 222222 & 3333333 & 44444444 & 55555555 & 66666666 & 77777777 & 88888888 \\
111111 & 222222 & 3333333 & 44444444 & 55555555 & 66666666 & 77777777 & 88888888 \\
111111 & 222222 & 3333333 & 44444444 & 55555555 & 66666666 & 77777777 & 88888888 \\
111111 & 222222 & 3333333 & 44444444 & 55555555 & 66666666 & 77777777 & 88888888 \\
111111 & 222222 & 3333333 & 44444444 & 55555555 & 66666666 & 77777777 & 88888888 \\
111111 & 222222 & 3333333 & 44444444 & 55555555 & 66666666 & 77777777 & 88888888 \\
111111 & 222222 & 3333333 & 44444444 & 55555555 & 66666666 & 77777777 & 88888888 \\
111111 & 222222 & 3333333 & 44444444 & 55555555 & 66666666 & 77777777 & 88888888 \\
111111 & 222222 & 3333333 & 44444444 & 55555555 & 66666666 & 77777777 & 88888888 \\
111111 & 222222 & 3333333 & 44444444 & 55555555 & 66666666 & 77777777 & 88888888 \\
111111 & 222222 & 3333333 & 44444444 & 55555555 & 66666666 & 77777777 & 88888888 \\
111111 & 222222 & 3333333 & 44444444 & 55555555 & 66666666 & 77777777 & 88888888 \\
111111 & 222222 & 3333333 & 44444444 & 55555555 & 66666666 & 77777777 & 88888888 \\
111111 & 222222 & 3333333 & 44444444 & 55555555 & 66666666 & 77777777 & 88888888 \\
111111 & 222222 & 3333333 & 44444444 & 55555555 & 66666666 & 77777777 & 88888888 \\
111111 & 222222 & 3333333 & 44444444 & 55555555 & 66666666 & 77777777 & 88888888 \\
111111 & 222222 & 3333333 & 44444444 & 55555555 & 66666666 & 77777777 & 88888888 \\
111111 & 222222 & 3333333 & 44444444 & 55555555 & 66666666 & 77777777 & 88888888 \\
111111 & 222222 & 3333333 & 44444444 & 55555555 & 66666666 & 77777777 & 88888888 \\
111111 & 222222 & 3333333 & 44444444 & 55555555 & 66666666 & 77777777 & 88888888 \\
111111 & 222222 & 3333333 & 44444444 & 55555555 & 66666666 & 77777777 & 88888888 \\
111111 & 222222 & 3333333 & 44444444 & 55555555 & 66666666 & 77777777 & 88888888 \\
111111 & 222222 & 3333333 & 44444444 & 55555555 & 66666666 & 77777777 & 88888888 \\
111111 & 222222 & 3333333 & 44444444 & 55555555 & 66666666 & 77777777 & 88888888 \\
111111 & 222222 & 3333333 & 44444444 & 55555555 & 66666666 & 77777777 & 88888888
\end{tabular}
}
\end{frame}

\end{document}
Related Question