[Tex/LaTex] adding section and subsection titles in footnote of presentation

beamersectioning

I want to show Section and subsection names in the footnote of a presentation, made by beamer. Now, in the footer, I am using

\insertsection\text{ $\quad \mid \quad $ }\insertsubsection

to create something like "Section title | subsection title"

However, for the sections without any subsection, I will still have "|" in the footnote.

Is there any way to insert "|" after section title if only there is a subsection title to be reported after that?

Best Answer

You can do a conditional test to decide whether or not to include the subsection titles; something along these lines:

\insertsectionhead
  \ifx\insertsubsectionhead\@empty\relax\else$\quad\mid\quad$\insertsubsectionhead\fi

A complete example (to diaply the information I used a beamercolorbox and the footline template, but this is optional; use the settings that best adjust to your needs):

\documentclass{beamer}

\makeatletter
\setbeamertemplate{footline}{%
\leavevmode
\vbox{\begin{beamercolorbox}[dp=1.25ex,ht=2.75ex]{fg=black}%
  \hspace*{1em}\insertsectionhead%
  \ifx\insertsubsectionhead\@empty\relax\else$\quad\mid\quad$\insertsubsectionhead\fi
  \end{beamercolorbox}%
  }%
}
\makeatother

\begin{document}

\section{Test section One}
\begin{frame}
test
\end{frame}
\subsection{Test subsection One One}
\begin{frame}
test
\end{frame}
\subsection{Test subsection One Two}
\begin{frame}
test
\end{frame}

\end{document}

enter image description here