=================

=================

我正在尝试定义自己的简约frametitle风格。我接近我想要的,但我很难获得自动化miniframes的子弹。

请参阅 MWE 以了解更多信息。

是否有任何简单的方法可以使用内置的项目符号导航来beamer miniframes获取我想要的内容?

(也请随意批评我做事的方式,因为这可能不应该做!)

梅威瑟:

\documentclass{beamer}
\usepackage{textcomp} % for \textopenbullet

\setbeamercolor{frametitle}{bg=black!20}

\setbeamertemplate{frametitle}
{
   \nointerlineskip
   \begin{beamercolorbox}[sep=0.0cm,ht=10mm,wd=\paperwidth]{frametitle}
      \vbox{}\vskip-0ex%
      \strut%
      \hspace*{4mm}\insertframetitle%
      \hfill{\scriptsize\insertframenumber/\inserttotalframenumber}\hspace*{0.5cm}%
      \ifx\insertframesubtitle
         \newline\hspace*{4mm}\small\strut\phantom{Pq}%
      \else
         \newline\hspace*{4mm}\small\strut\insertframesubtitle%
      \fi
   \end{beamercolorbox}
}

\addtobeamertemplate{frametitle}{
   \let\insertframetitle\insertsectionhead}{}
\addtobeamertemplate{frametitle}{
   \let\insertframesubtitle\insertsubsectionhead}{}

\makeatletter
  \CheckCommand*\beamer@checkframetitle{\@ifnextchar\bgroup\beamer@inlineframetitle{}}
  \renewcommand*\beamer@checkframetitle{\global\let\beamer@frametitle\relax\@ifnextchar\bgroup\beamer@inlineframetitle{}}
\makeatother

\begin{document}

\part{Part1}    
\section{Sec1}

\begin{frame}
   I would like to automatize the `navigation bullets' in the frametitle and in the framesubtitle. Here that would give:\\[5mm]
   Sec1 (\textbullet\textopenbullet\textopenbullet\textopenbullet\textopenbullet)
\end{frame}

\begin{frame}
   I would like to automatize the `navigation bullets' in the frametitle and in the framesubtitle. Here that would give:\\[5mm]
   Sec1 (\textbullet\textbullet\textopenbullet\textopenbullet\textopenbullet)
\end{frame}

\subsection{Subsec1.1}

\begin{frame}
   I would like to automatize the `navigation bullets' in the frametitle and in the framesubtitle. Here that would give:\\[5mm]
   Sec1 (\textbullet\textbullet\textbullet\textopenbullet\textopenbullet)\\
   Subsec1.1 (\textbullet\textopenbullet)
\end{frame}

\begin{frame}
   I would like to automatize the `navigation bullets' in the frametitle and in the framesubtitle. Here that would give:\\[5mm]
   Sec1 (\textbullet\textbullet\textbullet\textbullet\textopenbullet)\\
   Subsec1.1 (\textbullet\textbullet)
\end{frame}

\subsection{Subsec1.2}

\begin{frame}
   I would like to automatize the `navigation bullets' in the frametitle and in the framesubtitle. Here that would give:\\[5mm]
   Sec1 (\textbullet\textbullet\textbullet\textbullet\textbullet)\\
   Subsec1.1\\[5mm]
   Note that when there is only one frame in section or subsection, no bullets should be shown. 
\end{frame}

\section{Sec2}
\subsection{Subsec2.1}

\begin{frame}
   I would like to automatize the `navigation bullets' in the frametitle and in the framesubtitle. Here that would give:\\[5mm]
   Sec2 (\textbullet\textopenbullet\textopenbullet)\\
   Subsec2.1\\[5mm]
   Note that when there is only one frame in section or subsection, no bullets should be shown.    
\end{frame}

\subsection{Subsec2.2}

\begin{frame}
   I would like to automatize the `navigation bullets' in the frametitle and in the framesubtitle. Here that would give:\\[5mm]
   Sec2 (\textbullet\textbullet\textopenbullet)\\
   Subsec2.1 (\textbullet\textopenbullet)\\[1cm]
\end{frame}

\begin{frame}
   I would like to automatize the `navigation bullets' in the frametitle and in the framesubtitle. Here that would give:\\[5mm]
   Sec2 (\textbullet\textbullet\textbullet)\\
   Subsec2.1 (\textbullet\textbullet)\\[1cm]
\end{frame}

\end{document}

=================

编辑:离我想要的越来越近了,感谢 samcarter 的评论!但仍有几件事需要解决(参见新的 MWE)。

新 MWE:

\documentclass{beamer}
\usepackage{textcomp} % for \textopenbullet

\setbeamercolor{frametitle}{bg=black!20}

\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{etoolbox}

\makeatletter
\newcount\beamer@subsectionstartframe
\beamer@subsectionstartframe=1
\apptocmd{\beamer@subsection}{\addtocontents{nav}{\protect\headcommand{%
            \protect\beamer@subsectionframes{\the\beamer@subsectionstartframe}{\the\c@framenumber}}}}{}{}
\apptocmd{\beamer@subsection}{\beamer@subsectionstartframe=\c@framenumber\advance\beamer@subsectionstartframe by1\relax}{}{}
\AtEndDocument{\immediate\write\@auxout{\string\@writefile{nav}%
        {\noexpand\headcommand{\noexpand\beamer@subsectionframes{\the\beamer@subsectionstartframe}{\the\c@framenumber}}}}}{}{}
\def\beamer@startframeofsubsection{1}
\def\beamer@endframeofsubsection{1}
\def\beamer@subsectionframes#1#2{%
    \ifnum\c@framenumber<#1%
    \else%
    \ifnum\c@framenumber>#2%
    \else%
    \gdef\beamer@startframeofsubsection{#1}%
    \gdef\beamer@endframeofsubsection{#2}%
    \fi%
    \fi%
}
\newcommand\insertsubsectionstartframe{\beamer@startframeofsubsection}
\newcommand\insertsubsectionendframe{\beamer@endframeofsubsection}

\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

\newcounter{subsectionframenumber}
\newcounter{totalsubsectionframenumber}
\newcounter{sectionframenumber}
\newcounter{totalsectionframenumber}

\setbeamertemplate{frametitle}
{
   \nointerlineskip
   \begin{beamercolorbox}[sep=0.0cm,ht=10mm,wd=\paperwidth]{frametitle}
      \vbox{}\vskip-0ex%
      \strut%
      \hspace*{4mm}\insertframetitle\ (%
      \setcounter{sectionframenumber}{1}%
      \addtocounter{sectionframenumber}{\insertframenumber}%
      \addtocounter{sectionframenumber}{-\insertsectionstartframe}%
      \setcounter{totalsectionframenumber}{1}%
      \addtocounter{totalsectionframenumber}{\insertsectionendframe}%
      \addtocounter{totalsectionframenumber}{-\insertsectionstartframe}%
      \ifnum\value{section}>0%
      \foreach\x in {1,...,\value{totalsectionframenumber}}{%
          \ifnum \x<\numexpr\value{sectionframenumber}+1%
          \textbullet%
          \else%
          \textopenbullet%
          \fi%
      }%
      \fi%
      )%
      \hfill{\scriptsize\insertframenumber/\inserttotalframenumber}\hspace*{0.5cm}%
      \ifx\insertframesubtitle
         \newline\hspace*{4mm}\small\strut\phantom{Pq}%
      \else
         \newline\hspace*{4mm}\small\strut\insertframesubtitle\ (%
         \setcounter{subsectionframenumber}{1}%
         \addtocounter{subsectionframenumber}{\insertframenumber}%
         \addtocounter{subsectionframenumber}{-\insertsubsectionstartframe}%
         \setcounter{totalsubsectionframenumber}{1}%
         \addtocounter{totalsubsectionframenumber}{\insertsubsectionendframe}%
         \addtocounter{totalsubsectionframenumber}{-\insertsubsectionstartframe}%
         \ifnum\value{section}>0%
         \foreach\x in {1,...,\value{totalsubsectionframenumber}}{%
             \ifnum\x<\numexpr\value{subsectionframenumber}+1%
             \textbullet%
             \else%
             \textopenbullet%
             \fi%
         }%
         \fi%
      \fi%
      )%
   \end{beamercolorbox}
}

\addtobeamertemplate{frametitle}{
   \let\insertframetitle\insertsectionhead}{}
\addtobeamertemplate{frametitle}{
   \let\insertframesubtitle\insertsubsectionhead}{}

\makeatletter
  \CheckCommand*\beamer@checkframetitle{\@ifnextchar\bgroup\beamer@inlineframetitle{}}
  \renewcommand*\beamer@checkframetitle{\global\let\beamer@frametitle\relax\@ifnextchar\bgroup\beamer@inlineframetitle{}}
\makeatother


\begin{document}

\part{Part1}

\section{Sec1}

\begin{frame}
   I would like to automatize the `navigation bullets' in the frametitle and in the framesubtitle. Here that would give:\\[5mm]
   Sec1 (\textbullet\textopenbullet\textopenbullet\textopenbullet\textopenbullet)\\[5mm]

   \color{red}Note that when there is no subsection, no bullets should be shown.
\end{frame}

\begin{frame}
   I would like to automatize the `navigation bullets' in the frametitle and in the framesubtitle. Here that would give:\\[5mm]
   Sec1 (\textbullet\textbullet\textopenbullet\textopenbullet\textopenbullet)\\[5mm]

   \color{red}Note that when there is no subsection, no bullets should be shown.
\end{frame}

\subsection{Subsec1.1}

\begin{frame}
   I would like to automatize the `navigation bullets' in the frametitle and in the framesubtitle. Here that would give:\\[5mm]
   Sec1 (\textbullet\textbullet\textbullet\textopenbullet\textopenbullet)\\
   Subsec1.1 (\textbullet\textopenbullet)
\end{frame}

\begin{frame}
   I would like to automatize the `navigation bullets' in the frametitle and in the framesubtitle. Here that would give:\\[5mm]
   Sec1 (\textbullet\textbullet\textbullet\textbullet\textopenbullet)\\
   Subsec1.1 (\textbullet\textbullet)
\end{frame}


\subsection{Subsec1.2}

\begin{frame}
   I would like to automatize the `navigation bullets' in the frametitle and in the framesubtitle. Here that would give:\\[5mm]
   Sec1 (\textbullet\textbullet\textbullet\textbullet\textbullet)\\
   Subsec1.2\\[5mm]
   \color{red}Note that when there is only one frame in section or subsection, no bullets should be shown.
\end{frame}

\section{Sec2}

\subsection{Subsec2.1}

\begin{frame}
   I would like to automatize the `navigation bullets' in the frametitle and in the framesubtitle. Here that would give:\\[5mm]
   Sec2 (\textbullet\textopenbullet\textopenbullet)\\
   Subsec2.1\\[5mm]
   \color{red}Note that when there is only one frame in section or subsection, no bullets should be shown.
\end{frame}

\subsection{Subsec2.2}

\begin{frame}
   I would like to automatize the `navigation bullets' in the frametitle and in the framesubtitle. Here that would give:\\[5mm]
   Sec2 (\textbullet\textbullet\textopenbullet)\\
   Subsec2.2 (\textbullet\textopenbullet)\\[5mm]

   \color{red}I don't know why there is 3 bullets in the subsection here.
\end{frame}

\begin{frame}
   I would like to automatize the `navigation bullets' in the frametitle and in the framesubtitle. Here that would give:\\[5mm]
   Sec2 (\textbullet\textbullet\textbullet)\\
   Subsec2.2 (\textbullet\textbullet)\\[5mm]

   \color{red}I don't know why there is 3 bullets in the subsection here.
\end{frame}

\section{Sec3}

\begin{frame}
   I would like to automatize the `navigation bullets' in the frametitle and in the framesubtitle. Here that would give:\\[5mm]
   Sec3\\[5mm]

   \color{red}I don't know why there is 3 bullets in the subsection here.
\end{frame}

\end{document}

答案1

  • 当没有小节时,不应显示项目符号:你可以使用以下命令测试自己是否位于子部分之外\ifnum\thesubsection=0

  • 当章节或子章节中只有一帧时,不应显示项目符号:如果(子)部分中只有一个帧,则开始结束帧是相同的。这可以通过\ifnum\insertsubsectionstartframe=\insertsubsectionendframe和来测试\ifnum\insertsectionstartframe=\insertsectionendframe

  • 为什么本小节中有 3 个要点:我认为这归结为节结尾不被识别为小节结尾。作为一种解决方法,可以通过测试来发现这种情况\ifnum\insertsubsectionendframe<\insertsectionendframe


\documentclass{beamer}
\usepackage{textcomp} % for \textopenbullet

\setbeamercolor{frametitle}{bg=black!20}

\usepackage{tikz}
\usetikzlibrary{calc}
%\usepackage{etoolbox}

\makeatletter
\newcount\beamer@subsectionstartframe
\beamer@subsectionstartframe=1

\apptocmd{\beamer@subsection}{\addtocontents{nav}{\protect\headcommand{%
            \protect\beamer@subsectionframes{\the\beamer@subsectionstartframe}{\the\c@framenumber}}}}{}{}          

\apptocmd{\beamer@subsection}{\beamer@subsectionstartframe=\c@framenumber\advance\beamer@subsectionstartframe by1\relax}{}{}

\AtEndDocument{\immediate\write\@auxout{\string\@writefile{nav}%
        {\noexpand\headcommand{\noexpand\beamer@subsectionframes{\the\beamer@subsectionstartframe}{\the\c@framenumber}}}}}{}{}
\def\beamer@startframeofsubsection{1}
\def\beamer@endframeofsubsection{1}
\def\beamer@subsectionframes#1#2{%
    \ifnum\c@framenumber<#1%
    \else%
    \ifnum\c@framenumber>#2%
    \else%
    \gdef\beamer@startframeofsubsection{#1}%
    \gdef\beamer@endframeofsubsection{#2}%
    \fi%
    \fi%
}
\newcommand\insertsubsectionstartframe{\beamer@startframeofsubsection}
\newcommand\insertsubsectionendframe{\beamer@endframeofsubsection}

\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

\newcounter{subsectionframenumber}
\newcounter{totalsubsectionframenumber}
\newcounter{sectionframenumber}
\newcounter{totalsectionframenumber}
\newcounter{stopframe}

\setbeamertemplate{frametitle}
{
   \nointerlineskip
   \begin{beamercolorbox}[sep=0.0cm,ht=10mm,wd=\paperwidth]{frametitle}
      \vbox{}\vskip-0ex%
      \strut%
      \hspace*{4mm}\insertsectionhead%
      \ifnum\insertsectionstartframe=\insertsectionendframe%
      \else%
      \space(%
      \setcounter{sectionframenumber}{1}%
      \addtocounter{sectionframenumber}{\insertframenumber}%
      \addtocounter{sectionframenumber}{-\insertsectionstartframe}%
      \setcounter{totalsectionframenumber}{1}%
      \addtocounter{totalsectionframenumber}{\insertsectionendframe}%
      \addtocounter{totalsectionframenumber}{-\insertsectionstartframe}%
      \ifnum\value{section}>0%
      \foreach\x in {1,...,\value{totalsectionframenumber}}{%
          \ifnum \x<\numexpr\value{sectionframenumber}+1%
          \textbullet%
          \else%
          \textopenbullet%
          \fi%
      }%
      \fi%
      )%
      \fi%
      \hfill{\scriptsize\insertframenumber/\inserttotalframenumber}\hspace*{0.5cm}%
      \ifnum\thesubsection=0
         \newline\hspace*{4mm}\small\strut\phantom{Pq}%
      \else
             \newline\hspace*{4mm}\small\strut\insertsubsectionhead%
             \ifnum\insertsubsectionstartframe=\insertsubsectionendframe%
             \else%
             \space(%
             \setcounter{subsectionframenumber}{1}%
             \addtocounter{subsectionframenumber}{\insertframenumber}%
             \addtocounter{subsectionframenumber}{-\insertsubsectionstartframe}%
             \setcounter{totalsubsectionframenumber}{1}%
             \ifnum\insertsubsectionendframe<\insertsectionendframe
                \addtocounter{totalsubsectionframenumber}{\insertsubsectionendframe}%
             \else%
                   \addtocounter{totalsubsectionframenumber}{\insertsectionendframe}%
             \fi%
             \addtocounter{totalsubsectionframenumber}{-\insertsubsectionstartframe}%
             \ifnum\value{section}>0%
             \foreach\x in {1,...,\value{totalsubsectionframenumber}}{%
                 \ifnum\x<\numexpr\value{subsectionframenumber}+1%
                 \textbullet%
                 \else%
                 \textopenbullet%
                 \fi%
             }%
             \fi%
             )%
           \fi%  
      \fi%
   \end{beamercolorbox}
}

\makeatletter
  \CheckCommand*\beamer@checkframetitle{\@ifnextchar\bgroup\beamer@inlineframetitle{}}
  \renewcommand*\beamer@checkframetitle{\global\let\beamer@frametitle\relax\@ifnextchar\bgroup\beamer@inlineframetitle{}}
\makeatother


\begin{document}

\part{Part1}

\section{Sec1}

\begin{frame}
   I would like to automatize the `navigation bullets' in the frametitle and in the framesubtitle. Here that would give:\\[5mm]
   Sec1 (\textbullet\textopenbullet\textopenbullet\textopenbullet\textopenbullet)\\[5mm]

   \color{red}Note that when there is no subsection, no bullets should be shown.
\end{frame}

\begin{frame}
   I would like to automatize the `navigation bullets' in the frametitle and in the framesubtitle. Here that would give:\\[5mm]
   Sec1 (\textbullet\textbullet\textopenbullet\textopenbullet\textopenbullet)\\[5mm]

   \color{red}Note that when there is no subsection, no bullets should be shown.
\end{frame}

\subsection{Subsec1.1}

\begin{frame}
   I would like to automatize the `navigation bullets' in the frametitle and in the framesubtitle. Here that would give:\\[5mm]
   Sec1 (\textbullet\textbullet\textbullet\textopenbullet\textopenbullet)\\
   Subsec1.1 (\textbullet\textopenbullet)
\end{frame}

\begin{frame}
   I would like to automatize the `navigation bullets' in the frametitle and in the framesubtitle. Here that would give:\\[5mm]
   Sec1 (\textbullet\textbullet\textbullet\textbullet\textopenbullet)\\
   Subsec1.1 (\textbullet\textbullet)
\end{frame}


\subsection{Subsec1.2}

\begin{frame}
   I would like to automatize the `navigation bullets' in the frametitle and in the framesubtitle. Here that would give:\\[5mm]
   Sec1 (\textbullet\textbullet\textbullet\textbullet\textbullet)\\
   Subsec1.2\\[5mm]
   \color{red}Note that when there is only one frame in section or subsection, no bullets should be shown.
\end{frame}

\section{Sec2}

\subsection{Subsec2.1}

\begin{frame}
   I would like to automatize the `navigation bullets' in the frametitle and in the framesubtitle. Here that would give:\\[5mm]
   Sec2 (\textbullet\textopenbullet\textopenbullet)\\
   Subsec2.1\\[5mm]
   \color{red}Note that when there is only one frame in section or subsection, no bullets should be shown.
\end{frame}

\subsection{Subsec2.2}

\begin{frame}
   I would like to automatize the `navigation bullets' in the frametitle and in the framesubtitle. Here that would give:\\[5mm]
   Sec2 (\textbullet\textbullet\textopenbullet)\\
   Subsec2.2 (\textbullet\textopenbullet)\\[5mm]

   \color{red}I don't know why there is 3 bullets in the subsection here.
\end{frame}

\begin{frame}
   I would like to automatize the `navigation bullets' in the frametitle and in the framesubtitle. Here that would give:\\[5mm]
   Sec2 (\textbullet\textbullet\textbullet)\\
   Subsec2.2 (\textbullet\textbullet)\\[5mm]

   \color{red}I don't know why there is 3 bullets in the subsection here.
\end{frame}

\section{Sec3}

\begin{frame}
   I would like to automatize the `navigation bullets' in the frametitle and in the framesubtitle. Here that would give:\\[5mm]
   Sec3\\[5mm]

   \color{red}I don't know why there is 3 bullets in the subsection here.
\end{frame}

\end{document}

相关内容