我看到一个 Beamer 演示文稿,导航栏中只显示 3 个项目(最后一个、当前突出显示的和下一个)。这怎么可能呢?我使用的是华沙主题,我有(到目前为止)7 个部分,所以导航栏是也长的…
答案1
这是一个可能的解决方案;想法是有两个辅助命令\prevsection
并将\nextsection
前一节和下一节的名称保存到当前节;这些命令将在headline
模板中用于显示所需的信息,而不是通常的导航栏。
\prevsection
的更新\nextsection
是在内部通过对 的重新定义完成的\beamer@section
。
\sectioni
您所要做的就是在命令、、\sectionii
...的强制参数中填写\sectionviii
要在导航栏中显示的信息。
\documentclass{beamer}
\usetheme{Warsaw}
\newcounter{prevsection}
\newcounter{nextsection}
\newcommand\prevsection{}
\newcommand\nextsection{}
\makeatletter
\long\def\beamer@section[#1]#2{%
\beamer@savemode%
\mode<all>%
\ifbeamer@inlecture%
\refstepcounter{section}%
\beamer@ifempty{#2}%
{\long\def\secname{#1}\long\def\lastsection{#1}}%
{\global\advance\beamer@tocsectionnumber by 1\relax%
\long\def\secname{#2}%
\long\def\lastsection{#1}%
\addtocontents{toc}{\protect\beamer@sectionintoc{\the\c@section}{#2}{\the\c@page}{\the\c@part}%
{\the\beamer@tocsectionnumber}}}%
{\let\\=\relax\xdef\sectionlink{{Navigation\the\c@page}{\noexpand\secname}}}%
\beamer@tempcount=\c@page\advance\beamer@tempcount by -1%
\beamer@ifempty{#1}{}{%
\addtocontents{nav}{\protect\headcommand{\protect\sectionentry{\the\c@section}{#1}{\the\c@page}{\secname}{\the\c@part}}}%
\addtocontents{nav}{\protect\headcommand{\protect\beamer@sectionpages{\the\beamer@sectionstartpage}{\the\beamer@tempcount}}}%
\addtocontents{nav}{\protect\headcommand{\protect\beamer@subsectionpages{\the\beamer@subsectionstartpage}{\the\beamer@tempcount}}}%
}%
\beamer@sectionstartpage=\c@page%
\beamer@subsectionstartpage=\c@page%
\def\insertsection{\expandafter\hyperlink\sectionlink}%
\def\insertsubsection{}%
\def\insertsubsubsection{}%
\def\insertsectionhead{\hyperlink{Navigation\the\c@page}{#1}}%
\def\insertsubsectionhead{}%
\def\insertsubsubsectionhead{}%
\def\lastsubsection{}%
\Hy@writebookmark{\the\c@section}{\secname}{Outline\the\c@part.\the\c@section}{2}{toc}%
\hyper@anchorstart{Outline\the\c@part.\the\c@section}\hyper@anchorend%
\beamer@ifempty{#2}{\beamer@atbeginsections}{\beamer@atbeginsection}%
\fi%
\beamer@resumemode
\setcounter{prevsection}{\thesection}%
\setcounter{nextsection}{\thesection}%
\addtocounter{prevsection}{-1}%
\gdef\prevsection{\csname section\romannumeral\theprevsection \endcsname}%
\addtocounter{nextsection}{1}%
\renewcommand\nextsection{\csname section\romannumeral\thenextsection \endcsname}%
}%
\setbeamertemplate{headline}
{%
\leavevmode%
\@tempdimb=2.4375ex%
\ifnum\beamer@subsectionmax<\beamer@sectionmax%
\multiply\@tempdimb by\beamer@sectionmax%
\else%
\multiply\@tempdimb by\beamer@subsectionmax%
\fi%
\ifdim\@tempdimb>0pt%
\advance\@tempdimb by 1.125ex%
\begin{beamercolorbox}[wd=.5\paperwidth,ht=\@tempdimb,right,rightskip=1em]{section in head/foot}%
\vbox to \@tempdimb{%
\ifnum\thesection=1 \else%
\vfill{\color{fg!40!bg}\prevsection}%
\fi%
\vfill\insertsectionhead%
\ifnum\thesection=\beamer@sectionmax \else%
\vfill{\color{fg!40!bg}\nextsection}%
\fi\vfill%
}%
\end{beamercolorbox}%
\begin{beamercolorbox}[wd=.5\paperwidth,ht=\@tempdimb]{subsection in head/foot}%
\vbox to\@tempdimb{\vfil\insertsubsectionnavigation{.5\paperwidth}\vfil}%
\end{beamercolorbox}%
\fi%
}%
\makeatother
% Here you put the names that will go in the navigation bar
\newcommand\sectioni{test one}
\newcommand\sectionii{test two}
\newcommand\sectioniii{test three}
\newcommand\sectioniv{test four}
\newcommand\sectionv{test five}
\newcommand\sectionvi{test six}
\newcommand\sectionvii{test seven}
\newcommand\sectionviii{test eight}
\begin{document}
\section{test one}
\begin{frame}test\end{frame}
\section{test two}
\begin{frame}test\end{frame}
\section{test three}
\begin{frame}test\end{frame}
\section{test four}
\begin{frame}test\end{frame}
\section{test five}
\begin{frame}test\end{frame}
\end{document}
一些标题图片:
答案2
我从这段代码中得出了一个更简单的解决方案:Beamer Warsaw 主题:减少导航栏中可见的子部分数量
除了第一页,我把三个部分标题都弄对了。如果你不介意只显示前两个标题,只需注释掉第一页的标题命令代码即可。
\documentclass{beamer}
\usetheme{Warsaw}
\makeatletter
% A new section definition to automatically set labels with the name: sec:sectionnumber
\let\oldsection\section
\renewcommand{\section}[1]{\oldsection{#1}\label{sec:\thesection}}
% A new subsection definition to automatically set labels with the name: sec:sectionnumber.subsectionnumer
\let\oldsubsection\subsection
\renewcommand{\subsection}[1]{\oldsubsection{#1}\label{sec:\thesection.\thesubsection}}
%init some calculators
\newcounter{calculator}
\newcounter{othercalculator}
\newcounter{calcmaxsec}
\newcounter{calcmaxsubsec}
\newcommand{\calcsubsection}[1]%procedure to get the name of section thissection+i
{
\setcounter{calculator}{\thesubsection}\addtocounter{calculator}{#1}
\@ifundefined{r@sec:\thesection.\thecalculator}{}{\color{fg!40!bg}
\nameref{sec:\thesection.\thecalculator}}
}
\newcommand{\calcsection}[1]%procedure to get the name of subsection thissection.thissubsection+i
{
\setcounter{othercalculator}{\thesection\addtocounter{othercalculator}{#1}
\@ifundefined{r@sec:\thesection}{}{\color{fg!40!bg}\nameref{sec:\theothercalculator}}
}
\newcommand{\Testframe}%some testframe definition
{
\begin{frame}
The Section: \thesection\\
The Subsection: \thesubsection\\
The Calculator: \thecalculator\\
The section calculator: \theothercalculator\\
Count\thesection
\end{frame}
}
%Defining the layout%%%%%%%%%%%%%%%%%%%%%%%%%%%
\setbeamertemplate{headline}
{%
\leavevmode%
\@tempdimb=1.5ex%
\ifnum\beamer@subsectionmax<\beamer@sectionmax%
\multiply\@tempdimb by\beamer@sectionmax%
\else%
\multiply\@tempdimb by\beamer@subsectionmax%
\fi%
\ifdim\@tempdimb>0pt%
\advance\@tempdimb by 1.1ex%
\begin{beamercolorbox}[wd=.5\paperwidth,ht= \@tempdimb,right,rightskip=1em]{section in head/foot}%
\vbox to \@tempdimb{%
\setcounter{calcmaxsec}{\thesection}\addtocounter{calcmaxsec}{-\beamer@sectionmax}
%this gives the first and the last headlines
\ifnum\thesection=1\vfill{\calcsection{+2}}\fi%
\ifnum\thesection=\beamer@sectionmax\vfill{\calcsection{-2}}\fi%
%this tells where the last and nextsection is
\ifnum\thesection>1\vfill{\calcsection{-1}}\fi%
\ifnum\thesection>0\vfill\insertsectionhead\fi
\ifnum\beamer@sectionmax>1{\ifnum\thecalcmaxsec<0 \vfill{\calcsection{1}}\fi}\fi
\vfill%
}%
\end{beamercolorbox}%
\begin{beamercolorbox}[wd=.5\paperwidth,ht=\@tempdimb]{subsection in head/foot}%
\vbox to \@tempdimb{%
\setcounter{calcmaxsubsec}{\thesubsection}\addtocounter{calcmaxsubsec}{-\beamer@subsectionmax}
\ifnum\thesubsection>1 \vfill{\calcsubsection{-1}}\fi%
\ifnum\thesubsection>0 \vfill\insertsubsectionhead\fi
\ifnum\beamer@subsectionmax>1{\ifnum\thecalcmaxsubsec<0\vfill{\calcsubsection{1}}\fi}\fi
\vfill%
}%
\end{beamercolorbox}%
\fi%
}%
\makeatother %%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\section{test one}\Testframe
\subsection{sub 1}\Testframe
\subsection{sub 2}\Testframe
\subsection{sub 3}\Testframe
\subsection{sub 4}\Testframe
\subsection{sub 5}\Testframe
\subsection{sub 6}\Testframe
\subsection{sub 7}\Testframe
\section{test two}\Testframe
\subsection{sub 1}\Testframe
\subsection{sub 2}\Testframe
\section{test three}\Testframe
\subsection{sub 1}\Testframe
\subsection{sub 2}\Testframe
\subsection{sub 3}\Testframe
\section{test four}\Testframe
\subsection{sub 1}\Testframe
\subsection{sub 2}\Testframe
\subsection{sub 3}\Testframe
\subsection{sub 4}\Testframe
\section{test five}\Testframe
\subsection{sub 1}\Testframe
\section{test six}\Testframe
\subsection{sub 1}\Testframe
\end{document}
顺便问一下,有什么办法可以让这个代码预览窗口变小一些吗?