目录中的标识未对齐

问题描述 投票:0回答:1

当章节编号至少为 10 时,在 LaTeX 的投影仪演示文稿中,小节编号与 TOC 中的章节标题不一致。此外,(子)小节编号和(子)小节标题之间的间距变小。我正在寻找一种通用方法来解决此问题,无论节号是至少 10、至少 100 还是小于 10。在这种情况下,我不必手动调整这些内容。有办法做到这一点吗?

\documentclass[9pt,trans,xcolor={table},envcountsect]{beamer} % Plain

\usefonttheme[onlymath]{serif}
\usetheme[shownavsym,right]{Aalborg}
\setbeamertemplate{navigation symbols}{\insertframenavigationsymbol \insertsectionnavigationsymbol \insertbackfindforwardnavigationsymbol} % Nav symbols
\setbeamertemplate{section in toc}[sections numbered] % Automatic enumeration of sections
%
\makeatletter
\newcommand{\ShiftSectionNumber}[1]{%
\beamer@tocsectionnumber=\numexpr#1+\beamer@tocsectionnumber}
\makeatother
%
\setbeamertemplate{subsection in toc}{\leavevmode\leftskip=3.14em\rlap{\hskip-2em\inserttocsectionnumber.\inserttocsubsectionnumber}\inserttocsubsection\par} % Automatic enumeration of subsections. WITH indentation of subsection numbers (\leftskip changed from 3.2em to 3.14em)
%
\setbeamertemplate{subsubsection in toc}{\leavevmode\leftskip=6.9em\rlap{\hskip-3em\inserttocsectionnumber.\inserttocsubsectionnumber.\inserttocsubsubsectionnumber}\inserttocsubsubsection\par} % Automatic enumeration of subsubsections. WITH indentation of subsubsection numbers (\leftskip changed from 3.14em to 6.9em, \hskip changed from -2em to -3em)
%
\begin{document}
%
\begin{frame}%[allowframebreaks]
    \frametitle{Overview}
    \tableofcontents
\end{frame}
%
\def \numbershift {0} % Increasing of enumeration of section numbers and theorems
\ShiftSectionNumber{\numbershift} % Increasing the enumeration of section numbers
\addtocounter{section}{\numbershift} % Theorem numbers follow section numbers
%
%
\section{First Section (1-digit section number)} %What happens if a very long section title is used?} % https://tex.stackexchange.com/questions/89708/indent-subsections-in-beamers-toc
\subsection{First Subsection}
\subsubsection{First Subsubsection}

\ShiftSectionNumber{8}
\section{Second Section (2-digit section number)} % https://imathworks.com/tex/tex-latex-beamer-how-to-get-subsection-indent-with-a-numbered-toc/
\subsection{Second Subsection}
\subsubsection{Second Subsubsection}

\ShiftSectionNumber{89}
\section{Third Section (3-digit section number)}
\subsection{Third Subsection}
\subsubsection{Third Subsubsection}
%
\begin{frame}[<+->]{Misaligned identation in TOC}
    Hello.
\end{frame}

\end{document}
latex indentation beamer tableofcontents
1个回答
0
投票
\documentclass[9pt,trans,xcolor={table},envcountsect]{beamer} % Plain

\usefonttheme[onlymath]{serif}
\usetheme[shownavsym,right]{Aalborg}
\setbeamertemplate{navigation symbols}{\insertframenavigationsymbol \insertsectionnavigationsymbol \insertbackfindforwardnavigationsymbol} % Nav symbols


\begin{document}


\makeatletter

\newlength{\secnumwidth}
\settowidth{\secnumwidth}{\the\beamer@sectionmax.\space}
\newlength{\subsecnumwidth}
\settowidth{\subsecnumwidth}{\the\[email protected]}
\newlength{\subsubsecnumwidth}
\settowidth{\subsubsecnumwidth}{\the\[email protected]}

\setbeamertemplate{section in toc}{%
  \leavevmode%
  % prevents the period to be printed with the first/last section option
  \ifnum\beamer@tempcount>\beamer@toclastsection
  \else
  \ifnum\beamer@tempcount>0
    \makebox[\secnumwidth][l]{\inserttocsectionnumber.}%
  \fi\fi%
  \inserttocsection\par%
}

\setbeamertemplate{subsection in toc}{%
\leavevmode\leftskip=\secnumwidth\rlap{\inserttocsectionnumber.\inserttocsubsectionnumber}\hspace*{\subsecnumwidth}\space\space\inserttocsubsection\par}

\setbeamertemplate{subsubsection in toc}{%
\leavevmode\leftskip=\dimexpr\subsecnumwidth+\secnumwidth\rlap{\hspace{0.8em}\inserttocsectionnumber.\inserttocsubsectionnumber.\inserttocsubsubsectionnumber}\hspace*{\subsubsecnumwidth}\space\space\inserttocsubsubsection\par}
\makeatother


\begin{frame}%[allowframebreaks]
    \frametitle{Overview}
    \tableofcontents
\end{frame}

\section{Section}

\subsection{Subsection}
\subsubsection{Subsubsection}

\section{Section}
\section{Section}
\section{Section}
\section{Section}
\section{Section}
\section{Section}
\section{Section}
\section{Section}
\section{Section}

\subsection{Subsection}
\subsubsection{Subsubsection}

\begin{frame}[<+->]{Misaligned identation in TOC}
    Hello.
\end{frame}

\end{document}

© www.soinside.com 2019 - 2024. All rights reserved.