[Tex/LaTex] adjust the array size to the size of the frame+Beamer

arraysbeamer

I inserted a table into a page of a presentation Beamer but the problem is that the array size exceeds the frame.
How to adjust the array size to the size of the frame?

Best Answer

You can resize a tabular to fit exactly inside the text block of the frame using the functionality provided by graphicx - loaded by default by the beamer class. More specifically, you can use \resizebox{<width>}{<height>}{<stuff>} to resize <stuff> to width <width> and height <height>. If you wish to maintain the aspect ratio of <stuff>, replace one of the lengths with !:

enter image description here

\documentclass{beamer}% http://ctan.org/pkg/beamer
\usepackage{booktabs}% http://ctan.org/pkg/booktabs
\begin{document}
\begin{frame}
  \frametitle{A large table that doesn't fit}

​  \begin{tabular}{*{26}{c}}
    \toprule
    A & B & C & D & E & F & G & H & I & J & K & L & M & N & O & P & Q & R & S & T & U & V & W & X & Y & Z \\
    \midrule
    01 & 02 & 03 & 04 & 05 & 06 & 07 & 08 & 09 & 10 & 11 & 12 & 13 &
      14 & 15 & 16 & 17 & 18 & 19 & 20 & 21 & 22 & 23 & 24 & 25 & 26 \\
    26 & 25 & 24 & 23 & 22 & 21 & 20 & 19 & 18 & 17 & 16 & 15 & 14 &
      13 & 12 & 11 & 10 & 09 & 08 & 07 & 06 & 05 & 04 & 03 & 02 & 01 \\
    \bottomrule
  \end{tabular}
\end{frame}

\begin{frame}
  \frametitle{A large table that does fit!}

  \resizebox{\textwidth}{!}{%
  \begin{tabular}{*{26}{c}}
    \toprule
    A & B & C & D & E & F & G & H & I & J & K & L & M & N & O & P & Q & R & S & T & U & V & W & X & Y & Z \\
    \midrule
    01 & 02 & 03 & 04 & 05 & 06 & 07 & 08 & 09 & 10 & 11 & 12 & 13 &
      14 & 15 & 16 & 17 & 18 & 19 & 20 & 21 & 22 & 23 & 24 & 25 & 26 \\
    26 & 25 & 24 & 23 & 22 & 21 & 20 & 19 & 18 & 17 & 16 & 15 & 14 &
      13 & 12 & 11 & 10 & 09 & 08 & 07 & 06 & 05 & 04 & 03 & 02 & 01 \\
    \bottomrule
  \end{tabular}%
  }
\end{frame}
\end{document}​

Of course, this also shrinks the font size (actually everything, including the rule widths). If this is not ideal, you can use some methods provided in Column padding in tables (to remove some space) or perhaps reduce the number of columns altogether. Perhaps even displaying them on separate frames using column selection. For this see Easiest way to delete a column?

Although the above discussion references tabular, it applies equally to array as well. The syntax would resemble

\resizebox{\textwidth}{!}{%
  $\begin{array}{<col spec>}
    %...
  \end{array}$%
}