当使用 beamer 类时,如何创建一个表格,保存标题的内容和跨多页的列宽,而不明确命名这个宽度?
longtable 似乎保留了宽度,但正如在使用 beamer 和 longtable 在不同的幻灯片上使用相同的标题它似乎没有保留标题。另一方面,xtab 和 supertabular 似乎没有保留宽度。
答案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}
答案2
在我看来,最好的选择是使用常规环境在您需要的框架上复制表格的结构tabular
。
对于标题,也复制标题,但使用\widthof{...}
(来自calc
包裹)来获取跨框架的间距。 的参数\widthof{...}
应为跨所有框架的列中最宽元素:
\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}
\widthof{...}
将确保保留水平间距而无需重新指定它(在字面/长度意义上,例如50pt
)。