Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question

2 Answers 2

\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}
share|improve this answer

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).

share|improve this answer
    
it maybe a good idea to load the package calc which you already mentioned ... ;-) –  Herbert Sep 10 '11 at 20:09
    
@Herbert: Keen eye...! Thanks. –  Werner Sep 10 '11 at 20:09

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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