带有部分和子部分的进度条,投影仪

带有部分和子部分的进度条,投影仪

我正在使用 beamer 进行演示,我想在幻灯片的顶部添加一个进度条。我希望它类似于此处显示的内容:(Beamer:如何添加带有章节标题的进度条?)。但是,我不仅需要章节标题,还需要当前子章节的标题。如果子章节标题可以出现在其章节名称下方,那就完美了。

有人能帮我吗?提前谢谢了,

答案1

这是首次尝试添加当前子节。唯一的问题是当子节包含 p、q 和 y 等字母时会跳转(例如从幻灯片 2 更改为 3)。也许是锚点问题,但我不知道如何解决它。

代码:我为每项添加或更改都添加了注释。希望我没有忘记任何内容。

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{calc,patterns.meta}
% To provide total amount of sections throughout the document
\usepackage{totcount}
% Registers de total amount of sections (see https://tex.stackexchange.com/a/192506/141947)
\regtotcounter{section}
% To be able to refer to sections when needed
\usepackage{nameref}
% Redefinition of the \section command so that each one is labeled \label{sec:n} where n is its index 
\let\oldsection\section
\renewcommand{\section}[2][\relax]{%
    \ifx#1\relax
      \oldsection{#2}%
    \else
      \oldsection[#1]{#2}%
    \fi%
    \label{sec:\thesection}%
}

% ADDED:
\let\oldsubsection\subsection
\renewcommand{\subsection}[2][\relax]{%
    \ifx#1\relax
      \oldsubsection{#2}%
    \else
      \oldsubsection[#1]{#2}%
    \fi%
    \label{subsec:\thesection-\thesubsection}%
}

% Definition of custom colors based on the initial figure of the bar by the OP
\definecolor{myblue}{HTML}{57AED1}
\definecolor{mygreen}{HTML}{8BC53F}
\definecolor{mygray}{HTML}{DDDDDD}

% Definition of custom tikz styles in order to ease readability
\tikzset{
    % Bar style (Argument : color)
    sectionbar/.style={
        % Filling with one color as a preaction, in order to avoid reset by the pattern color
        preaction={fill=#1!70},
        % Application of the line pattern on to of the fill
        pattern={Lines[angle=45,distance={6pt},line width=3pt]},pattern color=#1
    },
    % Node style (Arguments : color, section number)
    sectionnode/.style 2 args={
        fill=#1,
        draw=white,
        thick,
        circle,
        text=white,
        radius=10pt,
        % Display of the section name below the cicle
        label={[text=#1,align=center]below:\nameref{sec:#2}\\~},% CHANGED
        },
    % ADDED: Node style (Arguments : color, section number, subsection number)
    sectionnodeWithSubsection/.style n args={3}{
        fill=#1,
        draw=white,
        thick,
        circle,
        text=white,
        radius=10pt,
        % Display of the section name and the subsection name below the cicle
        label={[text=#1,align=center]below:\nameref{sec:#2}\\-- \nameref{subsec:#2-#3} --},
        }
}


% Actual definition of the colorbar based on Gonzalo Medina's initial proposal
\makeatletter
    \def\pbar@progressbar{} % the progress bar
    \newcount\pbar@tmpcnta% auxiliary counter
    \newcount\pbar@tmpcntb% auxiliary counter
    \newdimen\pbar@pbht %progressbar height
    \newdimen\pbar@pbwd %progressbar width
    \newdimen\pbar@tmpdim % auxiliary dimension
    \pbar@pbwd=\linewidth
    \pbar@pbht=4pt

% The progress bar
\def\pbar@progressbar{%
    \pbar@tmpcnta=\value{section} % tmpcnta stores the section number
    \pbar@tmpcntb=\totvalue{section} % tmbcountb sotres the total amount of sections
    \advance\pbar@tmpcntb by 1 % tmbcountb is advanced by 1 in order to have the last bar segment after the last node

    \begin{tikzpicture}[very thin]
        % Clipping scope to avoid tests for the bar dimensions
        \begin{scope}
        % Clipping path
        \path[rounded corners=2pt,clip] (0pt,{-\pbar@pbht/2}) rectangle (\pbar@pbwd,{\pbar@pbht/2});
        % Gray bar (from 0 to last section)
        \path[sectionbar=mygray] (0pt,{-\pbar@pbht/2}) rectangle (\linewidth,{\pbar@pbht/2});
        % Blue bar (from 0 to the current section)
        \path[sectionbar=myblue] (0pt,{-\pbar@pbht/2}) rectangle ({(\[email protected])*\linewidth/\pbar@tmpcntb},{\pbar@pbht/2});
        % Green bar (from current to next section)
        \path[sectionbar=mygreen] ({(\[email protected])*\linewidth/\pbar@tmpcntb},{-\pbar@pbht/2}) rectangle ({(\pbar@tmpcnta+0.5)*\linewidth/\pbar@tmpcntb},{\pbar@pbht/2});
        \end{scope}
        % Drawing of the nodes on top of the bars, based on the number of the current section
        \foreach \secnumber in {1,...,\totvalue{section}}{
            % Number is lower, section is past, blue color
            \ifnum\secnumber<\pbar@tmpcnta
                \node[sectionnode={myblue}{\secnumber}] at ({(\secnumber-0.5)*\linewidth/\pbar@tmpcntb},0) {\strut\secnumber};
            \fi
            % Number is equal, section is current, green color
            \ifnum\secnumber=\pbar@tmpcnta
                % CHANGED:
                % if we have a current subsection, show current subsection
                \ifnum\thesubsection>0
                    \node[sectionnodeWithSubsection={mygreen}{\secnumber}{\thesubsection}] at ({(\secnumber-0.5)*\linewidth/\pbar@tmpcntb},0) {\strut\secnumber};
                \else
                    \node[sectionnode={mygreen}{\secnumber}] at ({(\secnumber-0.5)*\linewidth/\pbar@tmpcntb},0) {\strut\secnumber};
                \fi
            \fi
            % Number is larger, to be done section, gray color
            \ifnum\secnumber>\pbar@tmpcnta
            \node[sectionnode={mygray}{\secnumber}] at ({(\secnumber-0.5)*\linewidth/\pbar@tmpcntb},0) {\strut\secnumber};
            \fi
        }
  \end{tikzpicture}%
}

\addtobeamertemplate{headline}{}
{%
  \begin{beamercolorbox}[wd=\paperwidth,ht=13ex,center,dp=1ex]{white}% CHANGED: value of ht
    \pbar@progressbar%
  \end{beamercolorbox}%
}
\makeatother

\begin{document}

\section{Introduction}

\begin{frame}
    \frametitle{Introduction}
    test
\end{frame}

\section{Motivation}
\subsection{Sub:Motivation}

\begin{frame}
    \frametitle{Motivation}
    test
\end{frame}

\section{Methodology}

\subsection{Experiments}
\begin{frame}
    \frametitle{Experiments}
    test
\end{frame}

\subsection{Statistics}
\begin{frame}
    \frametitle{Statistics}
    test
\end{frame}

\section{Results}

\subsection{Results 1}
\begin{frame}
    \frametitle{Results 1}
    test
\end{frame}

\subsection{Results 2}
\begin{frame}
    \frametitle{Results 2}
    test
\end{frame}

\section{Conclusion}

\begin{frame}
    \frametitle{Conclusion}
    test
\end{frame}
\end{document}

输出:

Beamer:带有部分和小节的进度条。

相关内容