如何为 Beamer 演示文稿创建美观的目录?
\documentclass{beamer}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\begin{document}
\frame{
\tableofcontents
}
\section{Foo bar}
\frame{}
\section{Foo bar}
\frame{}
\section{Foo bar}
\frame{}
\section{Foo bar}
\frame{}
\section{Foo bar}
\frame{}
\section{Foo bar}
\frame{}
\section{Foo bar}
\frame{}
\end{document}
答案1
TikZ 可能带来的过度解决方案:
\documentclass[svgnames]{beamer}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\pgfdeclarehorizontalshading{section shading}{2cm}{
color(0cm)=(LightSlateGrey);
color(2cm)=(gray!7);
color(3cm)=(LightSlateGrey!15)
}
\usepackage{tikz}
\tikzset{section number/.style={
draw=none,
rectangle,
left color=gray!40,
right color=gray!20!black,
minimum size=1.5em,
text=white,
},
section/.style={
draw=none,
rectangle,
shading=section shading,
minimum height=1.5em,
minimum width=0.9\textwidth,
text width=0.9\textwidth,
text=black,
align=left
}
}
\makeatletter
\setbeamertemplate{section in toc}{
\ifnum\the\beamer@tempcount<10 %check to pad with 0
\tikz[baseline=-0.5ex]\node[section number]{\,0\inserttocsectionnumber};%
\else
\tikz[baseline=-0.5ex]\node[section number]{\,\inserttocsectionnumber};%
\fi
\,%
\tikz[baseline=-0.5ex]\node[section]{\inserttocsection};
}
\makeatother
\begin{document}
\frame{
\tableofcontents
}
\section{A very long title for this section}
\frame{}
\section{Foo bar}
\frame{}
\section{Foo bar}
\frame{}
\section{Foo bar}
\frame{}
\section{Foo bar}
\frame{}
\section{Foo bar}
\frame{}
\section{Foo bar}
\frame{}
\section{Another long title}
\frame{}
\section{Foo bar}
\frame{}
\section{Foo bar}
\frame{}
\section{Foo bar}
\frame{}
\end{document}
结果:
注意:我认为可以用更优雅的方式实现beamercolorboxes
。在检查节号后,节号会稍微向右移动一点(如初始图片所示):这样做是为了在节号低于 10 时在节号前面放置一个 0。