检查给定编号的页面是否为部分页面

检查给定编号的页面是否为部分页面

我想测试给定的页面是否是 beamer 中的部分页面。

这个想法是绘制一个进度条,并“标记”下一节的位置。但是,为此我需要知道给定的页面是否是节页面,如果是,则执行某些操作。

这就是我绘制进度条的方式:

\setbeamertemplate{background}{%
    \progressbar@tmpcounta=\insertframenumber
    \progressbar@tmpcountb=\inserttotalframenumber
    \progressbar@tmpdim=\progressbar@progresswidth
    \multiply\progressbar@tmpdim by \progressbar@tmpcounta
    \divide\progressbar@tmpdim by \progressbar@tmpcountb

    \begin{tikzpicture}
        \useasboundingbox (0,0) rectangle (\the\paperwidth, \the\paperheight);
        \fill[color=FuwaWhite] (0,0) rectangle (12.8cm, 9.6cm);

        \ifnum\thepage=1\relax\else
            \draw[fill=FuwaGreen,draw=none] (0cm, 0cm) rectangle (\progressbar@tmpdim,0.05cm);
            \node[anchor=south] at(6.4cm, 0.1cm) {\color{FuwaAnthrazit}\tiny\insertdate};
            \node[anchor=south east] at(12.8cm, 0.1cm) {\color{FuwaAnthrazit}\tiny\insertframenumber/%
                \inserttotalframenumber};
        \fi
        \foreach \x in {1,...,\inserttotalframenumber} {%
            \progressbar@tmpdim=\progressbar@progresswidth
            \divide\progressbar@tmpdim by \totvalue{section}
            \draw[fill=FuwaGreen!50!FuwaBlack,draw=none] (\x*\progressbar@tmpdim, 0) rectangle (\x*\progressbar@tmpdim+0.05cm, 0.05cm);
        }
   \end{tikzpicture}
}

不管它们间距是均匀的,我希望它们的间距像节一样。所以我会迭代每一页并检查该页是否是节页(即 beamer 认为的节页),然后绘制一些东西。

答案1

我可能无法检查它是否是部分页面,但我可以检查页面是否是部分的第一页。假设每个部分的第一页都是部分页面是否安全?

\documentclass{beamer}

\usepackage{etoolbox}
\makeatletter
\newcount\beamer@sectionstartframe
\beamer@sectionstartframe=1
\apptocmd{\beamer@section}{\addtocontents{nav}{\protect\headcommand{%
            \protect\beamer@sectionframes{\the\beamer@sectionstartframe}{\the\c@framenumber}}}}{}{}
\apptocmd{\beamer@section}{\beamer@sectionstartframe=\c@framenumber\advance\beamer@sectionstartframe by1\relax}{}{}
\AtEndDocument{\immediate\write\@auxout{\string\@writefile{nav}%
        {\noexpand\headcommand{\noexpand\beamer@sectionframes{\the\beamer@sectionstartframe}{\the\c@framenumber}}}}}{}{}
\def\beamer@startframeofsection{1}
\def\beamer@endframeofsection{1}
\def\beamer@sectionframes#1#2{%
    \ifnum\c@framenumber<#1%
    \else%
    \ifnum\c@framenumber>#2%
    \else%
    \gdef\beamer@startframeofsection{#1}%
    \gdef\beamer@endframeofsection{#2}%
    \fi%
    \fi%
}
\newcommand\insertsectionstartframe{\beamer@startframeofsection}
\newcommand\insertsectionendframe{\beamer@endframeofsection}
\makeatother

\setbeamertemplate{headline}{%
    \ifnum\insertsectionstartframe=\insertframenumber%
        \Huge I'm section!
    \fi%
    }

\begin{document}

    \section{The First}

    \begin{frame}
        First slide
    \end{frame}

    \begin{frame}
        Second slide
    \end{frame}

    \begin{frame}
        Third slide
    \end{frame}

    \begin{frame}
        Fourth slide
    \end{frame}

    \section{The Second}

    \begin{frame}
        First slide
    \end{frame}

    \begin{frame}
        Second slide
    \end{frame}

    \begin{frame}
        Third slide
    \end{frame}

\end{document}

相关内容