2

I am using the Singapore theme with subsections=true. Everything is OK with the position of both sections and navigation dots.

However, I would like the subsection title to appear below its corresponding section and section dots, instead of being left-align.

In the MWE below, I would like "Subsection 2.1" to be align below "Section 2", not below "Section 1".

Any idea? Thanks for your help!

MWE:

\documentclass[compress]{beamer}
\usetheme{Singapore}

\makeatletter
\beamer@theme@subsectiontrue
\makeatother

%------------------------------------%
\begin{document}

\section{Section 1}
\subsection{Subsection 1.1}
\begin{frame}
\begin{itemize}
    \item Text
\end{itemize}
\end{frame}

\subsection{Subsection 1.2}
\begin{frame}
\begin{itemize}
    \item Text
\end{itemize}
\end{frame}


\section{Section 2}
\subsection{Subsection 2.1}
\begin{frame}
\begin{itemize}
    \item Text
\end{itemize}
\end{frame}

\subsection{Subsection 2.2}
\begin{frame}
\begin{itemize}
    \item Text
\end{itemize}
\end{frame}


\section{Section 3}
\subsection{Subsection 3.1}
\begin{frame}
\begin{itemize}
    \item Text
\end{itemize}
\end{frame}

\subsection{Subsection 3.2}
\begin{frame}
\begin{itemize}
    \item Text
\end{itemize}
\end{frame}



\end{document}

Ex:

2
  • Use only \documentclass{beamer} (withuot compress) Commented May 21, 2022 at 21:16
  • Thanks for your help @SimonDispa
    – ynrn
    Commented May 22, 2022 at 13:50

1 Answer 1

1

Not a perfect alignment, but if your section/subsection titles don't differ too much in length, this should put the subsections approximately below the sections:

\documentclass[compress]{beamer}

\usepackage{pgffor}
\makeatletter
\setbeamercolor{section in head/foot}{use=structure,bg=structure.fg!25!bg}

\useoutertheme[subsection=true]{miniframes}

% total number of sections %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{totcount}
\newcounter{totalsection}
\regtotcounter{totalsection}

\AtBeginDocument{%
  \pretocmd{\section}{\refstepcounter{totalsection}}{}{}%
}%

\setbeamertemplate{headline}{%
  \begin{beamercolorbox}[colsep=1.5pt]{upper separation line head}
  \end{beamercolorbox}
  \begin{beamercolorbox}{section in head/foot}
    \vskip2pt\insertnavigation{\paperwidth}\vskip2pt
  \end{beamercolorbox}%
  \ifbeamer@theme@subsection%
    \begin{beamercolorbox}[colsep=1.5pt]{middle separation line head}
    \end{beamercolorbox}
    \begin{beamercolorbox}[ht=5pt]{subsection in head/foot}
    \makebox[\paperwidth]{    
      \usebeamercolor[fg]{subsection in head/foot}
      \usebeamerfont{subsection in head/foot}%
      \mbox{}\hfilneg\hfilneg\foreach \x in {1,...,\thesection}{\hfil}%
      \insertsubsectionhead
      \foreach \x in {\thesection,...,\totvalue{totalsection}}{\hfil}\hfilneg\hfilneg\mbox{}%
    }%
    \end{beamercolorbox}
  \fi%
  \begin{beamercolorbox}[colsep=1.5pt]{lower separation line head}
  \end{beamercolorbox}
}


\setbeamertemplate{frametitle}[default][center]

\AtBeginDocument{%
  {
    \usebeamercolor{section in head/foot}
  }
  
  \pgfdeclareverticalshading{beamer@headfade}{\paperwidth}
  {%
    color(0cm)=(bg);
    color(1.25cm)=(section in head/foot.bg)%
  }

  \setbeamercolor{section in head/foot}{bg=}
}

\addtoheadtemplate{\pgfuseshading{beamer@headfade}\vskip-1.25cm}{}

\beamertemplatedotitem

\makeatother

%------------------------------------%
\begin{document}

\section{Section 1}
\subsection{Subsection 1.1}
\begin{frame}
\begin{itemize}
    \item Text
\end{itemize}
\end{frame}

\subsection{Subsection 1.2}
\begin{frame}
\begin{itemize}
    \item Text
\end{itemize}
\end{frame}


\section{Section 2}
\subsection{Subsection 2.1}
\begin{frame}
\begin{itemize}
    \item Text
\end{itemize}
\end{frame}

\subsection{Subsection 2.2}
\begin{frame}
\begin{itemize}
    \item Text
\end{itemize}
\end{frame}


\section{Section 3}
\subsection{Subsection 3.1}
\begin{frame}
\begin{itemize}
    \item Text
\end{itemize}
\end{frame}

\subsection{Subsection 3.2}
\begin{frame}
\begin{itemize}
    \item Text
\end{itemize}
\end{frame}

\end{document}

enter image description here

2
  • In the second beamercolorbox after \ifbeamer@theme@subsection% you are writing {sEubsection in head/foot}. Shouldn't it be subsection instead of seubsection?
    – Jim
    Commented May 21, 2023 at 21:04
  • @Jim Thanks for finding this typo! You are of course correct, that should read subsection in head/foot. Commented May 21, 2023 at 21:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .