1

I am trying to use capital roman numerals (I, II, ...) to present each section in my beamer TOC with its section number. The following MWE works overall, but it can be seen that the roman numbers, and thus also the section titles, are not aligned. Instead, the roman numbers are left-aligned, and the distance between section number and title is fixed, thus shifting sections to the right depending on the width of the roman numeral.

[During the creation of this MWE, I wanted to have the second section the number 25, to visualize the problem better, as XXV is much wider than I (compared to II). However, despite setting the section counter to 24 and thesection being correctly set at 25 in the frame title, the inserttocsectionnumber command in the TOC only produces a 2 instead of 25. It would be good if there was a solution for that problem as well, i.e. to force TOC to take actual section numbers instead of what seems to be its own count.]

\documentclass[t, sansserif, onlymath, 10pt]{beamer}%\mode<handout>

\makeatletter
\defbeamertemplate{section in toc}{sections numbered roman}{%
  \@Roman\inserttocsectionnumber.\ %
  \inserttocsection\par}
  \renewcommand*{\numberline}[1]{%
  \hb@xt@\@tempdima{\hfil#1 }%
}
\makeatother

\begin{document}

\setbeamertemplate{section in toc}[sections numbered roman]
\setbeamerfont{section in toc}{size=\normalsize, family = \sffamily}
\setbeamerfont{section in toc}{shape = \normalfont}

\begin{frame}
  \frametitle{Overview}
  \tableofcontents[currentsection]
\end{frame}
\section{section one}
\begin{frame}
  \frametitle{xxx1 \thesection}
\end{frame}

\setcounter{section}{24}

\section{section two/twenty-five}
\begin{frame}
  \frametitle{xxx2 \thesection}
\end{frame}

\setbeamercovered{transparent}
\begin{frame}
\frametitle{{Agenda}}   
\begin{enumerate}[I.]
\item <1|handout: 1> { Overview} \\
\vspace{0.9cm}
\item <0|handout: 1> {sec1}\\
\vspace{0.9cm}
\item <0|handout: 1> {sec 2: }\\
\end{enumerate}
\end{frame}

\end{document}

Including the last slide gives pretty much how I want the result to look (in fact, it is where I am coming from, but I need automation). You can see that, using the "enumerate" package, the "enumerations" are right-aligned, and so are the section titles.

In the document preamble, the code

  \defbeamertemplate{section in toc}{sections numbered roman}{%
  \@Roman\inserttocsectionnumber.\ %
  \inserttocsection\par}

serves to use roman numerals and insert section numbers before section titles, and

  \renewcommand*{\numberline}[1]{%
  \hb@xt@\@tempdima{\hfil#1 }%
  }

tries to right-align the number using a command taken from Right-align numbers in ToC , but that is rather on alignment between sections and subsections relative to each other, and the above code snipped does not do the trick.

2

Quick workaround:

place the Roman number in a boxed of fixed width

\documentclass[t, sansserif, onlymath, 10pt]{beamer}%\mode<handout>

\makeatletter
\defbeamertemplate{section in toc}{sections numbered roman}{%
  \makebox[0.8cm]{\hfill\@Roman\inserttocsectionnumber.}\space%
  \inserttocsection\par
}
\makeatother

\begin{document}

\setbeamertemplate{section in toc}[sections numbered roman]

\begin{frame}
  \frametitle{Overview}
  \tableofcontents
\end{frame}

\section{section one}
\begin{frame}
  \frametitle{xxx1 \thesection}
\end{frame}

\makeatletter
\beamer@tocsectionnumber=24
\makeatother

\section{section two/twenty-five}
\begin{frame}
  \frametitle{xxx2 \thesection}
\end{frame}

\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.