评论:

评论:

在我相当长的演示文稿中,我尝试编写一个带有章节、小节和框架导航项目符号的 Beamer 主题,如下图所示 迷你章节、迷你子章节和迷你框架导航项目符号

我发现没有内置主题可以满足我的需求。那么我们该如何实现呢?

答案1

可能有更好的方法可以做到这一点,但我不想弄乱投影仪导航,而是想尝试一些新的东西并使用该xcntperchap软件包。

评论:

  • 需要两次编译
  • 没有提供可点击的链接

在此处输入图片描述

\documentclass{beamer}
\usepackage{tikz}

\usepackage{totcount}
\regtotcounter{section}

\usepackage{xcntperchap}
\RegisterCounters{section}{subsection}

\newcounter{totalsubsection}
\setcounter{totalsubsection}{0}
\usepackage{etoolbox}

\preto\frame{\setcounter{totalsubsection}{\ObtainTrackedValueExp[\value{section}]{section}{subsection}}}

\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

\usetikzlibrary{calc}

\def\inserttotalsectionframenumber{%
    \pgfmathparse{(\insertsectionendframe-\insertsectionstartframe+1)}%
    \pgfmathprintnumber[fixed,precision=2]{\pgfmathresult}%
}

\def\insertsectionframenumber{%
    \pgfmathparse{(\insertframenumber-\insertsectionstartframe+1)}%
    \pgfmathprintnumber[fixed,precision=2]{\pgfmathresult}%
}

\newcounter{sectionframenumber}
\newcounter{totalsectionframenumber}

\setbeamertemplate{headline}{%
    \vskip1em%
    \hbox{%  
        \begin{beamercolorbox}[wd=.3\paperwidth,ht=2.25ex,dp=1ex]{section in head/foot}%
            \centering%
            \insertsection\par%
            \vskip0.2em%
            \foreach\x in {1,...,\totvalue{section}}{%
                \ifnum\x=\value{section}%
                \usebeamertemplate{mini frame}~%
                \else%
                \usebeamertemplate{mini frame in other section}~%
                \fi%
            }%
        \end{beamercolorbox}%
        \begin{beamercolorbox}[wd=.3\paperwidth,ht=2.25ex,dp=1ex]{subsection in head/foot}%
            \ifnum\value{totalsubsection}>0%
            \centering%
            \insertsubsection\par%
            \vskip0.2em%
            \foreach\x in {1,...,\value{totalsubsection}}{%
                \ifnum\x=\value{subsection}%
                \usebeamertemplate{mini frame}~%
                \else%
                \usebeamertemplate{mini frame in other subsection}~%
                \fi%
            }%
            \fi%
        \end{beamercolorbox}%
        \begin{beamercolorbox}[wd=.3\paperwidth,ht=2.25ex,dp=1ex]{section in head/foot}%
            \centering%
            \ifx\insertframetitle\empty\else%
                \insertframetitle\par%
            \fi%
            \vskip0.2em%
            \setcounter{sectionframenumber}{1}
            \addtocounter{sectionframenumber}{\insertframenumber}
            \addtocounter{sectionframenumber}{-\insertsectionstartframe}
            \setcounter{totalsectionframenumber}{1}
            \addtocounter{totalsectionframenumber}{\insertsectionendframe}
            \addtocounter{totalsectionframenumber}{-\insertsectionstartframe}
            \foreach\x in {1,...,\value{totalsectionframenumber}}{%
                \ifnum\x=\value{sectionframenumber}%
                \usebeamertemplate{mini frame}~%
                \else%
                \usebeamertemplate{mini frame in other subsection}~%
                \fi%
            }%
        \end{beamercolorbox}%       
    }}

    \def\insertframetitle{}

    \begin{document}    
        \section{Section1}
        \subsection{Subsection1}
        \begin{frame}
            \frametitle{Frame11}
        \end{frame}

        \subsection{Subsection2}
        \begin{frame}
            \frametitle{Frame12}
        \end{frame}

        \section{Section2}
        \begin{frame}
            \frametitle{Frame2}
        \end{frame}

        \subsection{Subsection1}
        \begin{frame}
            \frametitle{Frame21}
        \end{frame}

        \subsection{Subsection2}
        \begin{frame}
            \frametitle{Frame22}
        \end{frame}

        \subsection{Subsection3}
        \begin{frame}
            \frametitle{Frame23}
        \end{frame}

        \section{Section3}
        \begin{frame}
            \frametitle{Frame3}
        \end{frame}

        \frame{}

    \end{document}

相关内容