我正在用 Beamer 的华沙主题做一个演示,标题结构如下:
\setbeamertemplate{headline}{%
\leavevmode%
\hbox{%
\begin{beamercolorbox}[wd=\paperwidth,ht=2.5ex,dp=1.125ex]{palette quaternary}%
\insertsectionnavigationhorizontal{\paperwidth}{}{\hskip0pt plus1filll}
\end{beamercolorbox}%
}
}
如何只显示三个部分,或者像这样,前一个-当前-后一个部分,并突出显示当前部分?由于我有大量部分(约 10 个),因此无法在标题中显示所有部分。请提出建议。
答案1
\documentclass{beamer}
\usetheme{Warsaw}
\AtBeginSection[]{\label{sec:\thesection}}
\usepackage{totcount}
\newcounter{totalsection}
\regtotcounter{totalsection}
\AtBeginDocument{%
\pretocmd{\section}{\refstepcounter{totalsection}}{}{}%
}%
\newcounter{start}
\newcounter{stop}
\usepackage{pgffor}
\setbeamercolor{section in head/foot}{fg=white}
\setbeamercolor{section in head/foot shaded}{fg=white!60!bg}
\setbeamertemplate{headline}{%
\leavevmode%
\hbox{%
\begin{beamercolorbox}[wd=\paperwidth,ht=2.5ex,dp=1.125ex]{palette quaternary}%
\ifnum\value{section}>0%
\quad
\setcounter{start}{\value{section}}
\setcounter{stop}{\value{section}}
\ifnum\value{section}>1
\addtocounter{start}{-1}
\fi
\ifnum\value{section}<\totvalue{totalsection}
\addtocounter{stop}{1}
\fi
\foreach \i in {\thestart,...,\thestop}{%
\ifnum\i=\value{section}
\usebeamercolor[fg]{section in head/foot}
\else
\usebeamercolor[fg]{section in head/foot shaded}
\fi
\hfill\hyperlink{sec:\i}{\nameref{sec:\i}}
}
\hfill\quad
\fi
\end{beamercolorbox}%
}
}
\begin{document}
\section{test1}\begin{frame}abc\end{frame}
\section{test2}\begin{frame}abc\end{frame}
\section{test3}\begin{frame}abc\end{frame}
\section{test4}\begin{frame}abc\end{frame}
\section{test5}\begin{frame}abc\end{frame}
\section{test6}\begin{frame}abc\end{frame}
\section{test7}\begin{frame}abc\end{frame}
\section{test8}\begin{frame}abc\end{frame}
\section{test9}\begin{frame}abc\end{frame}
\section{test10}\begin{frame}abc\end{frame}
\section{test11}\begin{frame}abc\end{frame}
\end{document}