[Tex/LaTex] Customizing the sidebar in beamer having aligned section numbers

alignbeamer

I'd like to know how the vertical navigation in the beamer sidebar can be edited to have the section numbers aligned left like in a toc.

The question is very similar to this one I think the MWE can be used, too.

To make clearer what I want to achieve I uploaded a picture of a beamer theme (non-public) having the alignment implemented:

enter image description here

As you can see the section number is fixed left of section title and the subsection starts at the exact same x-position like the section. Also line break start at that x-position. Also other texts like title are fixed at this position.

Thanks in advance!

Best Answer

You can do this using side-by-side \parboxes for the numbers and the titles; change \secinsidebarindent (dafault=10pt) to control the width of the box reserved for the numbers:

\documentclass{beamer}
\usetheme{Marburg}

\newlength\secinsidebarindent
\setlength\secinsidebarindent{10pt}

\makeatletter
  \setbeamertemplate{sidebar \beamer@sidebarside}
  {
    \beamer@tempdim=\beamer@sidebarwidth%
    \advance\beamer@tempdim by -6pt%
    \vskip4em%
    \insertverticalnavigation{\beamer@sidebarwidth}%
    \vfill
    \ifx\beamer@sidebarside\beamer@lefttext%
    \else%
      \usebeamercolor{normal text}%
      \llap{\usebeamertemplate***{navigation symbols}\hskip0.1cm}%
      \vskip2pt%
    \fi%
  }%

  \ifx\beamer@sidebarside\beamer@lefttext%
    \defbeamertemplate*{sidebar right}{sidebar theme}
    {%
      \vfill%
      \llap{\usebeamertemplate***{navigation symbols}\hskip0.1cm}%
      \vskip2pt}
  \fi

\setbeamertemplate{section in sidebar}%{sidebar theme}
{%
  \vbox{%
    \vskip1ex%
    \beamer@sidebarformat{3pt}{section in sidebar}{%
      \parbox[t]{\secinsidebarindent}{\insertsectionheadnumber\hfill}%
      \parbox[t]{\dimexpr\beamer@sidebarwidth-\secinsidebarindent-6pt\relax}{\raggedright\insertsectionhead}}%
  }%
}
\setbeamertemplate{section in sidebar shaded}%{sidebar theme}
{%
  \vbox{%
    \vskip1ex%
    \beamer@sidebarformat{3pt}{section in sidebar shaded}{%
      \parbox[t]{\secinsidebarindent}{\insertsectionheadnumber\hfill}%
      \parbox[t]{\dimexpr\beamer@sidebarwidth-\secinsidebarindent-6pt\relax}{\raggedright\insertsectionhead}}%
  }%
}
\setbeamertemplate{subsection in sidebar}%{sidebar theme}
{%
  \vbox{%
    \vskip2ex%
    \beamer@sidebarformat{3pt}{subsection in sidebar}{%
      \parbox[t]{\secinsidebarindent}{\hfill}%
      \parbox[t]{\dimexpr\beamer@sidebarwidth-\secinsidebarindent-6pt\relax}{\raggedright\insertsubsectionhead}}%
  }%
}
\setbeamertemplate{subsection in sidebar shaded}%{sidebar theme}
{%
  \vbox{%
    \vskip2ex%
    \beamer@sidebarformat{3pt}{subsection in sidebar shaded}{%
      \parbox[t]{\secinsidebarindent}{\hfill}%
      \parbox[t]{\dimexpr\beamer@sidebarwidth-\secinsidebarindent-6pt\relax}{\raggedright\insertsubsectionhead}}%
  }%
}
\makeatother

\begin{document}

\section{First test section with a long title}
\begin{frame} test \end{frame}
\subsection{A test subsection}
\begin{frame} test \end{frame}

\section{Second test section with another long title}
\begin{frame} test \end{frame}
\subsection{A test subsection}
\begin{frame} test \end{frame}

\section{Yet another section}
\begin{frame} test \end{frame}
\subsection{A test subsection}
\begin{frame} test \end{frame}

\end{document}

An image showing the resulting sidebar:

enter image description here