Beamer Warsaw 主题:减少导航栏中可见的子部分数量

Beamer Warsaw 主题:减少导航栏中可见的子部分数量

我的讲座有 10 个部分,大概有 5-10 个子部分。使用华沙主题会使可用空间太小。

有没有办法让导航栏显示:

  • 仅最后一节、当前节和接下来的两节?
  • 仅最后一小节、当前小节和接下来的两个小节?

如果没有选项,可能必须改变\insertsubsectionnavigation功能。

也许类似

\insertsubsectionnavigation["\thissectionnumber-1" to "\thissectionnumber+2"] 

问题是:我不明白这个功能的工作方式。

有人有类似主题的想法或链接吗?

下面是一个不应该出现的例子:

\documentclass{beamer}
\usetheme{Warsaw}
\begin{document}
    \section{Section 1}
    \section{Section 2}
    \section{Section 3}
    \section{Section 4}
        \subsection{SubSection a}\begin{frame}Test\end{frame}
        \subsection{SubSection b}\begin{frame}Test\end{frame}
        \subsection{SubSection c}\begin{frame}Test\end{frame}
        \subsection{SubSection d}\begin{frame}Test\end{frame}
        \subsection{SubSection e}\begin{frame}Test\end{frame}
        \subsection{SubSection f}\begin{frame}Test\end{frame}
        \subsection{SubSection g}\begin{frame}Test\end{frame}
        \subsection{SubSection h}\begin{frame}Test\end{frame}
        \subsection{SubSection i}\begin{frame}Test\end{frame}
    \section{Section 5}
    \section{Section 6}
    \section{Section 7}\begin{frame}Test\end{frame}
\end{document}

幻灯片看起来如下: 正常风格

我希望它看起来像: 在此处输入图片描述

答案1

这是@GonzaloMedina 回答的扩展导航栏中只有 3 个项目,可能吗?也涵盖了小节(后面是长的 Beamer 代码)。

\documentclass{beamer}
\usetheme{Warsaw}

\newcounter{prevsection}
\newcounter{nextsection}
\newcounter{prevsubsection}
\newcounter{nextsubsection}


\newcommand\prevsection{}
\newcommand\nextsection{}
\newcommand\prevsubsection{}
\newcommand\nextsubsection{}

\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}%
}%

\def\beamer@subsection[#1]#2{%
  \beamer@savemode%
  \mode<all>%
  \ifbeamer@inlecture%
    \refstepcounter{subsection}%
    \beamer@ifempty{#2}{\long\def\subsecname{#1}\long\def\lastsubsection{#1}}
    {%
      \long\def\subsecname{#2}%
      \long\def\lastsubsection{#1}%
      \addtocontents{toc}{\protect\beamer@subsectionintoc{\the\c@section}{\the\c@subsection}{#2}{\the\c@page}{\the\c@part}{\the\beamer@tocsectionnumber}}%
    }%
    \beamer@tempcount=\c@page\advance\beamer@tempcount by -1%
    \addtocontents{nav}{%
      \protect\headcommand{\protect\beamer@subsectionentry{\the\c@part}{\the\c@section}{\the\c@subsection}{\the\c@page}{\lastsubsection}}%
      \protect\headcommand{\protect\beamer@subsectionpages{\the\beamer@subsectionstartpage}{\the\beamer@tempcount}}%
    }%
    \beamer@subsectionstartpage=\c@page%
    \edef\subsectionlink{{Navigation\the\c@page}{\noexpand\subsecname}}%
    \def\insertsubsection{\expandafter\hyperlink\subsectionlink}%
    \def\insertsubsubsection{}%
    \def\insertsubsectionhead{\hyperlink{Navigation\the\c@page}{#1}}%
    \def\insertsubsubsectionhead{}%
    \Hy@writebookmark{\the\c@subsection}{#2}{Outline\the\c@part.\the\c@section.\the\c@subsection.\the\c@page}{3}{toc}%
    \hyper@anchorstart{Outline\the\c@part.\the\c@section.\the\c@subsection.\the\c@page}\hyper@anchorend%
    \beamer@ifempty{#2}{\beamer@atbeginsubsections}{\beamer@atbeginsubsection}%
  \fi%
  \beamer@resumemode
  \setcounter{prevsubsection}{\thesubsection}%
    \setcounter{nextsubsection}{\thesubsection}%
    \addtocounter{prevsubsection}{-1}%
    \gdef\prevsubsection{\csname subsection\romannumeral\theprevsubsection \endcsname}%
     \addtocounter{nextsubsection}{1}%
    \renewcommand\nextsubsection{\csname subsection\romannumeral\thenextsubsection \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{%
      \ifnum\thesubsection=1 \else%
        \vfill{\color{fg!40!bg}\prevsubsection}%
      \fi%
        \vfill\insertsubsectionhead%
      \ifnum\thesubsection=\beamer@subsectionmax \else%
        \vfill{\color{fg!40!bg}\nextsubsection}%
     \fi\vfill%
     }%
    \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\subsectioni{sub 1}
\newcommand\subsectionii{sub 2}
\newcommand\subsectioniii{sub 3}
\newcommand\subsectioniv{sub 4}

\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}
\subsection{sub 1}
\begin{frame}test\end{frame}
\subsection{sub 2}
\begin{frame}test\end{frame}
\subsection{sub 3}
\begin{frame}test\end{frame}
\subsection{sub 4}
\begin{frame}test\end{frame}

\end{document}

在此处输入图片描述

答案2

完成的代码如下。首先,我更新了\section\subsection添加了自动引用。我创建了函数\calcsubsection[i]\calcsection[i]获取节的名称“sectionnumber+i”或“subsectionnumber+i”,其中 i 表示未来节,i 表示较早节。例如: \calcsubsection{-1}给出当前节中上一个子节名称的名称。 \calcsubsection{1}给出当前节中的下一个子节名称。

我明天要开始上课了,所以我现在要用这个解决方案。如果有人能对改进代码、当出现的子节少于节时的布局提出意见,我会很高兴

我确实花了很长时间来创建这个代码,因为我从来没有真正使用过“latex 的这一部分”。抱歉,旧的“答案”不是这个论坛想要的答案。我删除了它们。

\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{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{calculator}{\thesection}\addtocounter{calculator}{#1}
    \@ifundefined{r@sec:\thesection}{}{\color{fg!40!bg}\nameref{sec:\thecalculator}}
}
\newcommand{\Testframe}%some testframe definition
    {
        \begin{frame}
            The Section: \thesection\\
            The Subsection: \thesubsection\\
            The Calculator: \thecalculator\\
            Count\thesection
        \end{frame}
    }
%Defining the layout%%%%%%%%%%%%%%%%%%%%%%%%%%%
\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{%
        \setcounter{calcmaxsec}{\thesection}\addtocounter{calcmaxsec}{-\beamer@sectionmax}
        \ifnum\thecalcmaxsec>-1\vfill{\calcsection{-3}}\fi%
        \ifnum\thecalcmaxsec>-2\vfill{\calcsection{-2}}\fi%
        \ifnum\thesection>1\vfill{\calcsection{-1}}\fi%
        \ifnum\thesection>0\vfill\insertsectionhead\fi
        \ifnum\thecalcmaxsec<0\vfill{\calcsection{1}}\fi
        \ifnum\thecalcmaxsec<-1\vfill{\calcsection{2}}\fi
        \ifnum\thesection<2\vfill{\calcsection{3}}\fi
        \ifnum\thesection<1\vfill{\calcsection{4}}\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\thecalcmaxsubsec>-1 \vfill{\calcsubsection{-3}}\fi%
        \ifnum\thecalcmaxsubsec>-2 \vfill{\calcsubsection{-2}}\fi%
        \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
        \ifnum\beamer@subsectionmax>2{\ifnum\thecalcmaxsubsec<-1\vfill{\calcsubsection{2}}\fi}\fi
        \ifnum\beamer@subsectionmax>3{\ifnum\thesubsection<2\vfill{\calcsubsection{3}}\fi}\fi
        \ifnum\beamer@subsectionmax>4{\ifnum\thesubsection<1\vfill{\calcsubsection{4}}\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}

相关内容