4

When using the beamer class, how can I create a table which preservers the contents of the header and the width of the columns across multiple pages, without naming this width explicitly?

longtable seems to preserve the width, but as already described in Same Header on different slides with beamer and longtable it seems not to preserve the header. xtab and supertabular on the other hand seem not to preserve the width.

1
\documentclass{beamer}
\begin{document}
\begin{frame}{My frame title}
  \begin{tabular}{cc}
    This is a very long header & Here is another header \\ \hline
    fooooooooooo & Bar\\ 
    fooooooooooo & Bar\\ 
    fooooooooooo & Bar\\ 
    fooooooooooo & Bar\\ 
    fooooooooooo & Bar\\ 
    fooooooooooo & Bar\\ 
  \end{tabular}
\end{frame}
\begin{frame}{My frame title}
  \begin{tabular}{cc}
  \rlap{Different header}\phantom{This is a very long header} & 
  \rlap{Short header}\phantom{Here is another header} \\ \hline
    fooooooooooo & Bar\\ 
    fooooooooooo & Bar\\ 
    fooooooooooo & Bar\\ 
    fooooooooooo & Bar\\ 
    fooooooooooo & Bar\\ 
    fooooooooooo & Bar\\ 
  \end{tabular}
\end{frame}
\end{document}
| improve this answer | |
1

Your best bet here, in my opinion, is to duplicate the structure of your table on the frames that you need using a regular tabular environment.

In terms of headers, also duplicate the header but use \widthof{...} (from the calc package) to get the spacing right across frames. The argument of \widthof{...} should be the widest element within the column across all frames:

\documentclass{beamer}
\usepackage{lmodern}% http://ctan.org/pkg/lmodern
\usepackage{calc}% http://ctan.org/pkg/calc
\begin{document}
\begin{frame}{My frame title}
  \begin{tabular}{cc}
    This is a very long header & Here is another header \\ \hline
    fooooooooooo & Bar\\ 
    fooooooooooo & Bar\\ 
    fooooooooooo & Bar\\ 
    fooooooooooo & Bar\\ 
    fooooooooooo & Bar\\ 
    fooooooooooo & Bar\\ 
  \end{tabular}
\end{frame}
\begin{frame}{My frame title}
  \begin{tabular}{cc}
  \makebox[\widthof{This is a very long header}][c]{Different header} & 
  \makebox[\widthof{Here is another header}][c]{Short header} \\ \hline
    fooooooooooo & Bar\\ 
    fooooooooooo & Bar\\ 
    fooooooooooo & Bar\\ 
    fooooooooooo & Bar\\ 
    fooooooooooo & Bar\\ 
    fooooooooooo & Bar\\ 
  \end{tabular}
\end{frame}
\end{document}

Using \widthof to duplicate tabular header widths

\widthof{...} will ensure that the horizontal spacing is preserved without respecifying it (in the literal/length sense, as in 50pt, say).

| improve this answer | |
  • it maybe a good idea to load the package calc which you already mentioned ... ;-) – user2478 Sep 10 '11 at 20:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.