Beamer 自动编号章节和小节

Beamer 自动编号章节和小节

如何自动对章节和小节进行编号,以便当它们的顺序发生变化时,使用以下代码自动调整编号

    \documentclass{beamer}
\usepackage{verbatim}
\setbeamertemplate{navigation symbols}{}

\setbeamercolor{author}{fg=blue}
\setbeamerfont{title}{size=\Large, series=\bfseries}
\setbeamerfont{subtitle}{size=\Large, series=\bfseries}
\setbeamerfont{author}{size=\footnotesize}
\setbeamerfont{date}{size=\small}

\setbeamertemplate{section page}
{
\begingroup
\begin{beamercolorbox}[sep=10pt,center,rounded=true,shadow=true]{section title}
    \usebeamerfont{section title}\insertsection\par
\end{beamercolorbox}
\endgroup
}

\setbeamertemplate{subsection page}
{
\begingroup
\begin{beamercolorbox}[sep=2pt,center,rounded=true,shadow=true]{section title}
    \usebeamerfont{section title}\insertsection\par
\end{beamercolorbox}
\vspace*{-1.pt}
\begin{beamercolorbox}[sep=6pt,center,rounded=true,shadow=true]{subsection title}
    \usebeamerfont{subsection title}\insertsubsection\par
\end{beamercolorbox}
\endgroup
}

    \setbeamerfont{section title}{size=\Large,series=\bfseries}
    \setbeamerfont{subsection title}{size=\large,series=\bfseries}

\begin{document}


\begin{frame}
\titlepage
\end{frame} 

\begin{frame}[t]
\frametitle{Table of Contents}
\tableofcontents
\end{frame}


\setbeamercolor{section title}{bg=blue!40}
\setbeamercolor{subsection title}{bg=blue!20}

\section{Immortal Games}
\frame{\sectionpage}

\subsection{Anderssen-Kieseritzky 1851}
\frame{\subsectionpage}

\subsection{Sliwa-Bronstein 1957}
\frame{\subsectionpage}

\subsection{Opera Game}
\frame{\subsectionpage}

\subsection{Alekhine`s Gun Game}
\frame{\subsectionpage}


\section{Famous Games}
\frame{\sectionpage}

\subsection{Byrne-Fischer}
\frame{\subsectionpage}

\subsection{Evergreen Game}
\frame{\subsectionpage}

\subsection{Deep Blue vs Kasparov}
\frame{\subsectionpage}

\subsection{Caruana vs Wojtkiewicz}
\frame{\subsectionpage}

\end{document}

答案1

在 Latex 中,章节和小节的编号是自动的 - 所以我想你的问题可能是如何显示这些数字?

  1. 要显示它们,请执行以下操作toc

    \setbeamertemplate{section in toc}[sections numbered]
    \setbeamertemplate{subsection in toc}[subsections numbered]
    
  2. 在您的章节和子章节页面上:您可以将数字添加到您的定义中,例如\thesection.\thesubsection~\insertsubsection


\documentclass{beamer}

\setbeamertemplate{navigation symbols}{}
\setbeamertemplate{section in toc}[sections numbered]
\setbeamertemplate{subsection in toc}[subsections numbered]

\setbeamercolor{author}{fg=blue}
\setbeamercolor{section title}{bg=blue!40}
\setbeamercolor{subsection title}{bg=blue!20}

\setbeamerfont{title}{size=\Large, series=\bfseries}
\setbeamerfont{subtitle}{size=\Large, series=\bfseries}
\setbeamerfont{author}{size=\footnotesize}
\setbeamerfont{date}{size=\small}
\setbeamerfont{section title}{size=\Large,series=\bfseries}
\setbeamerfont{subsection title}{size=\large,series=\bfseries}

\setbeamertemplate{section page}{%
    \begingroup
        \begin{beamercolorbox}[sep=10pt,center,rounded=true,shadow=true]{section title}
        \usebeamerfont{section title}\thesection~\insertsection\par
        \end{beamercolorbox}
    \endgroup
}

\setbeamertemplate{subsection page}{%
    \begingroup
        \begin{beamercolorbox}[sep=2pt,center,rounded=true,shadow=true]{section title}
        \usebeamerfont{section title}\thesection~\insertsection\par
        \end{beamercolorbox}
        \vspace*{-1.pt}
        \begin{beamercolorbox}[sep=6pt,center,rounded=true,shadow=true]{subsection title}
        \usebeamerfont{subsection title}\thesection.\thesubsection~\insertsubsection\par
        \end{beamercolorbox}
    \endgroup
}

\AtBeginSection[]{%
    \begin{frame}
        \sectionpage
    \end{frame}
}

\AtBeginSubsection[]{%
    \begin{frame}
        \subsectionpage
    \end{frame}
}

\begin{document}

\begin{frame}[t]
    \frametitle{Table of Contents}
    \tableofcontents
\end{frame}

\section{Immortal Games}
\subsection{Anderssen-Kieseritzky 1851}
\subsection{Sliwa-Bronstein 1957}
\subsection{Opera Game}
\subsection{Alekhine`s Gun Game}
\section{Famous Games}
\subsection{Byrne-Fischer}
\subsection{Evergreen Game}
\subsection{Deep Blue vs Kasparov}
\subsection{Caruana vs Wojtkiewicz}

\end{document}

答案2

(我并没有真正看过你的代码

您可以使用以下宏来访问章节和小节编号:

\the\beamer@tocsectionnumber% section number
\thesubsection% subsection number

为了检测未编号的章节和小节,我使用以下代码:

\documentclass[]{beamer}


\makeatletter
\newif\ifStarredSubsection@
\newif\ifStarredSection@

\AtBeginSection[%>>>
  \global\StarredSection@true%
]{%
  \global\StarredSection@false%
}%<<<
\AtBeginSubsection[%>>>
  \global\StarredSubsection@true%
]{%
  \global\StarredSubsection@false%
}%<<<

\newcommand*{\mycursec}{%
    \ifStarredSection@%
    \else%
      \makebox[24pt][l]{\the\beamer@tocsectionnumber.}%
    \fi%
  \insertsection}
\newcommand*{\mycurssec}{%
    \ifStarredSubsection@%
    \else%
      \ifnum\c@subsection>0\relax%
        \makebox[24pt][l]{\the\beamer@tocsectionnumber.\thesubsection}%
      \fi%
    \fi%
  \insertsubsection}
\makeatother

\begin{document}

\section{foo}
\subsection{bar}

\begin{frame}{\mycursec}{\mycurssec}
  Frame with section and subsection as title and subtitle
\end{frame}


\end{document}

相关内容