使用 Beamer 在 LaTeX 中制作仅包含罗马数字的导航标题

使用 Beamer 在 LaTeX 中制作仅包含罗马数字的导航标题

我正在用 Beamer 用 LaTeX 制作演示文稿,我想有一个由两部分组成的标题:

  • 在第一部分中,我将使用罗马字体显示所有部分的所有编号。我还希望活动部分的数字为白色,就像普通文本一样,而其他数字的透明度较低,不太显眼。此外,每个数字都是一个链接,重定向到相应部分开始的页面。事实上,它完全一样,\insertsectionnavigationhorizontal{.5\paperwidth}{}{\hskip0pt plus1filll}%但用的是部分的罗马数字而不是部分的名称。
  • 在第二部分中,我将拥有活动部分的所有子部分,但没关系,我用 来完成\insertsubsectionnavigationhorizontal{.5\paperwidth}{}{\hskip0pt plus1filll}

我在我的其中一门课程中看到过它,它看起来像这样:

第一个图像示例 第二幅图示例 第三幅图示例

忽略星号,我不知道它们是什么意思。

我已经看过beamer 文档在页眉和页脚部分(8.2.1),但从我的角度来看,我没有发现任何有趣的东西。

我尝试了在互联网上找到的很多代码,并询问了 ChatGPT,但目前,我只能使用这个:

\setbeamertemplate{headline}
{
    \leavevmode%
    \hbox{%
        \begin{beamercolorbox}[wd=.5\paperwidth,ht=2.25ex,dp=1ex,right]{section in head/foot}%
            \usebeamerfont{section in head/foot} \insertsectionnavigationhorizontal{.5\paperwidth}{}{\hskip0pt plus1filll}%
        \end{beamercolorbox}%
        \begin{beamercolorbox}[wd=.5\paperwidth,ht=2.25ex,dp=1ex,left]{subsection in head/foot}%
            \usebeamerfont{subsection in head/foot}\insertsubsectionnavigationhorizontal{.5\paperwidth}{}{\hskip0pt plus1filll}
    \end{beamercolorbox}}%
    \vskip0pt%
}

完整代码如下:


\documentclass[aspectratio=169]{beamer}
\usetheme{Madrid}
\usecolortheme{whale}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage[]{lmodern}
\usepackage[]{hyperref}


\title{Presentation title}
\date{\today}
\author{A. Name\inst{1}}

\institute[Ex] % (optional)
{
    \inst{1}%
    Example\\
    Example
}

\makeatletter
\patchcmd{\beamer@sectionintoc}
{\vfill}
{\vskip15pt}
{}
{}
\makeatother  

\setbeamertemplate{headline}
{
    \leavevmode%
    \hbox{%
        \begin{beamercolorbox}[wd=.5\paperwidth,ht=2.25ex,dp=1ex,right]{section in head/foot}%
            \usebeamerfont{section in head/foot} \insertsectionnavigationhorizontal{.5\paperwidth}{}{\hskip0pt plus1filll}%
        \end{beamercolorbox}%
        \begin{beamercolorbox}[wd=.5\paperwidth,ht=2.25ex,dp=1ex,left]{subsection in head/foot}%
            \usebeamerfont{subsection in head/foot}\insertsubsectionnavigationhorizontal{.5\paperwidth}{}{\hskip0pt plus1filll}
    \end{beamercolorbox}}%
    \vskip0pt%
}


\begin{document}
\begin{frame}
    \maketitle
\end{frame}

\begin{frame}{Table of content}
      \begin{columns}[t]
        \begin{column}{5cm}
            \tableofcontents[sections={1-2},currentsection,sectionstyle=show,subsectionstyle=show]
        \end{column}
        \begin{column}{5cm}
            \tableofcontents[sections={3-4},currentsection,sectionstyle=show,subsectionstyle=show]
        \end{column}
    \end{columns}
%   \begin{center}
%       \tableofcontents
%   \end{center}
\end{frame}

\section{Section 1}
\subsection{Subsection 1}
\begin{frame}{Section 1}
\end{frame}

\subsection{Subsection 2}
\begin{frame}
    Lipsum
\end{frame}

\section{Section 2}
\begin{frame}{Section 2}
    Lipsum
\end{frame}

\section{Section 3}
\begin{frame}{Section 3}
    Lipsum
\end{frame}

\section{Section 4}
\begin{frame}{Section 4}
    Lipsum
\end{frame}
\end{document}

答案1

您可以重新定义\beamer@section宏并将罗马部分编号(而不是标题)传递给标题。

<- changes made here我在下面的代码中标记了更改的行:

\documentclass[aspectratio=169]{beamer}
\usetheme{Madrid}
\usecolortheme{whale}

%\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage[]{lmodern}
%\usepackage[]{hyperref}


\title{Presentation title}
\date{\today}
\author{A. Name\inst{1}}

\institute[Ex] % (optional)
{
    \inst{1}%
    Example\\
    Example
}

\makeatletter
\patchcmd{\beamer@sectionintoc}
{\vfill}
{\vskip15pt}
{}
{}
\makeatother  

\setbeamertemplate{headline}
{
    \leavevmode%
    \hbox{%
        \begin{beamercolorbox}[wd=.5\paperwidth,ht=2.25ex,dp=1ex,right]{section in head/foot}%
            \usebeamerfont{section in head/foot} \insertsectionnavigationhorizontal{.5\paperwidth}{}{\hskip0pt plus1filll}%
        \end{beamercolorbox}%
        \begin{beamercolorbox}[wd=.5\paperwidth,ht=2.25ex,dp=1ex,left]{subsection in head/foot}%
            \usebeamerfont{subsection in head/foot}\insertsubsectionnavigationhorizontal{.5\paperwidth}{}{\hskip0pt plus1filll}
    \end{beamercolorbox}}%
    \vskip0pt%
}


\makeatletter
\long\def\beamer@section[#1]#2{%
  \GetTitleString{#1}%
  \let\@currentlabelname\GetTitleStringResult
  \beamer@savemode%
  \mode<all>%
  \ifbeamer@inlecture
    \refstepcounter{section}%
    \ifblank{#2}%
    {\long\def\secname{#1}\long\def\lastsection{#1}}%
    {\global\advance\beamer@tocsectionnumber by 1\relax%
      \long\def\secname{#2}%
      \long\def\lastsection{#1}%
      \addtocontents{toc}{\protect\beamer@sectionintoc{\the\c@section}{#2}{\the\c@page}{\the\c@part}%
        {\the\beamer@tocsectionnumber}}}%
    {\let\\=\relax\xdef\sectionlink{{Navigation\the\c@page}{\noexpand\secname}}}%
    \beamer@tempcount=\c@page\advance\beamer@tempcount by -1%
    \addtocontents{nav}{\protect\headcommand{\protect\beamer@sectionpages{\the\beamer@sectionstartpage}{\the\beamer@tempcount}}}%
    \addtocontents{nav}{\protect\headcommand{\protect\beamer@subsectionpages{\the\beamer@subsectionstartpage}{\the\beamer@tempcount}}}%
    \ifblank{#1}{}{%
      \addtocontents{nav}{\protect\headcommand{\protect\sectionentry{\the\c@section}{\expandafter\@Roman\c@section}{\the\c@page}{\secname}{\the\c@part}}}% <- changes made here
    }%
    \beamer@sectionstartpage=\c@page%
    \beamer@subsectionstartpage=\c@page%
    \def\insertsection{\expandafter\hyperlink\sectionlink}%
    \def\insertsubsection{}%
    \def\insertsubsubsection{}%
    \def\insertsectionhead{\hyperlink{Navigation\the\c@page}{#1}}%
    \edef\insertsectionhead{\noexpand\hyperlink{Navigation\the\c@page}{\unexpanded{#1}}}%
    \def\insertsubsectionhead{}%
    \def\insertsubsubsectionhead{}%
    \def\lastsubsection{}%
    \Hy@writebookmark{\the\c@section}{\secname}{Outline\the\c@part.\the\c@section}{2}{toc}%
    \hyper@anchorstart{Outline\the\c@part.\the\c@section}\hyper@anchorend%
    \ifblank{#2}{\beamer@atbeginsections}{\beamer@atbeginsection}%
  \fi%
  \beamer@resumemode}%
\makeatother

\begin{document}
\begin{frame}
    \maketitle
\end{frame}

\begin{frame}{Table of content}
      \begin{columns}[t]
        \begin{column}{5cm}
            \tableofcontents[sections={1-2},currentsection,sectionstyle=show,subsectionstyle=show]
        \end{column}
        \begin{column}{5cm}
            \tableofcontents[sections={3-4},currentsection,sectionstyle=show,subsectionstyle=show]
        \end{column}
    \end{columns}
%   \begin{center}
%       \tableofcontents
%   \end{center}
\end{frame}

\section{Section 1}
\subsection{Subsection 1}
\begin{frame}{Section 1}
\end{frame}

\subsection{Subsection 2}
\begin{frame}
    Lipsum
\end{frame}

\section{Section 2}
\begin{frame}{Section 2}
    Lipsum
\end{frame}

\section{Section 3}
\begin{frame}{Section 3}
    Lipsum
\end{frame}

\section{Section 4}
\begin{frame}{Section 4}
    Lipsum
\end{frame}
\end{document}

在此处输入图片描述

相关内容