josephwright / beamer

A LaTeX class for producing presentations and slides
Other
1.41k stars 142 forks source link

Problem with long section title in table of contents #817

Closed Tex-Ahmadi closed 1 year ago

Tex-Ahmadi commented 1 year ago

test file:

\documentclass{beamer}
\usetheme{Berlin}

\title{Problem with long section title in table of contents}
\author{M.Ahmadi}

\begin{document}

\frame{\tableofcontents }

\section[My short title]{Suggestions for a Practical Implementation of the Modified Newton Method. A Rank-One Method Due to Broyden}

\begin{frame}
test
\end{frame}

\end{document}

test

in file beamerbaseauxtemplates.sty , row: 256-264

\defbeamertemplate{section in toc}{square}
{\leavevmode\leftskip=1.75ex%
  \llap{%
    \usebeamerfont*{section number projected}%
    \usebeamercolor[bg]{section number projected}%
    \vrule width2.25ex height1.85ex depth.4ex%
    \hskip-2.25ex%
    \hbox to2.25ex{\hfil\color{fg}\inserttocsectionnumber\hfil}}% <---- probleam  with }
  \kern1.25ex\inserttocsection\par}

Solved by replacing in beamerbaseauxtemplates.sty , row: 256-264

Note: replac } in row 263 after of \kern1.25ex } in row 264

\defbeamertemplate{section in toc}{square}
{\leavevmode\leftskip=1.75ex%
  \llap{%
    \usebeamerfont*{section number projected}%
    \usebeamercolor[bg]{section number projected}%
    \vrule width2.25ex height1.85ex depth.4ex%
    \hskip-2.25ex%
    \hbox to2.25ex{\hfil\color{fg}\inserttocsectionnumber\hfil}% 
  \kern1.25ex}\inserttocsection\par} 

Solution output:

solve11

samcarter commented 1 year ago

@Tex-Ahmadi Thanks for the report! I found a couple of other templates which are also effected by this problem, I will fix them as well.

samcarter commented 1 year ago

@josephwright I went through all the section in toc templates and identified two more which exhibit this problem. The ball unnumbered was straightforward to fix, but for the sections numbered I could use a second pair of eyes.

The original behaviour is

origional

Now I see three possible ways to fix this:

  1. Keep current behaviour.

  2. Make all labels same width. All entries will be aligned nicely, but for large numbers the space will get a bit tight

same_width

  1. Adapt to width of label. Will work for all numbers, but indentation will vary

adapt_width

What do you think?

josephwright commented 1 year ago

Tricky: I think with no clear 'good' option we leave as-is.

samcarter commented 1 year ago

Tricky: I think with no clear 'good' option we leave as-is.

Ok, that's the easiest solution :)

samcarter commented 1 year ago

Thanks for taking a look!

samcarter commented 1 year ago

Just parking the code here in case someone will revisit the topic in the future...

Indentation which adapts to the width of the label:

\newlength{\beamer@toclabelwidth}
\defbeamertemplate{section in toc}{sections numbered}{%
  \settowidth{\beamer@toclabelwidth}{\inserttocsectionnumber.}%
  \addtolength{\beamer@toclabelwidth}{1.5ex}%
  \leavevmode
  % prevents the period to be printed with the first/last section option
  \ifnum\beamer@tempcount>\beamer@toclastsection
  \else
  \ifnum\beamer@tempcount>0
    \leftskip=\beamer@toclabelwidth\hskip-\beamer@toclabelwidth%
    \hbox to\beamer@toclabelwidth{\inserttocsectionnumber.\hfil}%
  \fi\fi%
  \inserttocsection\par%
}

Fixed indentation:

\defbeamertemplate{section in toc}{sections numbered}{%
  \leavevmode
  % prevents the period to be printed with the first/last section option
  \ifnum\beamer@tempcount>\beamer@toclastsection
  \else
  \ifnum\beamer@tempcount>0
    \leftskip=3ex\hskip-3ex%
    \hbox to3ex{\inserttocsectionnumber.\hfil}%
  \fi\fi%
  \inserttocsection\par%
}