8

I'm within a beamer presentation (again) and trying to get a frame title to automatically print the title of the section from within a subsection. The code (with example of what I'd like to do) looks like this:

\documentclass{beamer}
\mode<presentation>
\title[Title]{Title}
\author{My Name}
\institute{Where I am}
\date{September 2013}
\begin{document}
\begin{frame}
\section{SECTION NAME}
\subsection{Subsection Name}
\begin{frame}{"SECTION NAME": Title of Frame}
Content
\end{frame}

To be clear, I'd like the "SECTION NAME" in quote marks to automatically pull the text of \section{SECTION NAME}

Thanks!

UPDATE:

Thanks to moewe, the solution was found. It comes from this article. The updated code looks like this:

\documentclass{beamer}
\usepackage{nameref}
\mode<presentation>
\title[Title]{Title}
\author{My Name}
\institute{Where I am}
\date{September 2013}
\begin{document}
\begin{frame}
\section{SECTION NAME}\label{itsname}
\subsection{Subsection Name}
\begin{frame}{\label{itsname}: Title of Frame}
Content
\end{frame}
5
  • 1
    Does Get the title instead of the number of a referenced chapter/section? help?
    – moewe
    Commented Sep 23, 2013 at 14:52
  • Yep - \nameref labels seem to work; however, they do require labels, which is labour intensive. For my purposes, this solution will work, though! Thanks.
    – putins
    Commented Sep 23, 2013 at 14:58
  • 1
    Well, you will have to have a label, otherwise you have no way of referring to (the title); you can read “Automatic” section labeling? about automatic labelling.
    – moewe
    Commented Sep 23, 2013 at 15:01
  • 1
    Your updated code can’t work as expected since you used \label twice but the second one should be a \ref ;-)
    – Tobi
    Commented Sep 23, 2013 at 22:44
  • 2
    @Tobi's answer is much more easy than the other solutions, should be the accepted answer I guess?
    – Simon C.
    Commented Nov 5, 2019 at 18:23

2 Answers 2

5

An alternative is without \nameref and without intensive labeling. This is possible because the section name is called from within a subsection and thus its higher level counter is available to utilized.

 \documentclass[]{beamer}

 \makeatletter
 \newcommand\newsection[1]{%
 \section{#1}    
 \@namedef{\thesection}{#1}         
 }

 \newcommand\newsec{% 
 \@nameuse{\thesection}
 }
 \makeatother

 \mode<presentation>
 \title[Title]{Title}
 \author{My Name}
 \institute{Where I am}
 \date{September 2013}

 \begin{document}
 \begin{frame}[t]
 \maketitle
 \end{frame}
 \begin{frame}[t]
 \tableofcontents
 \end{frame}
 \begin{frame}[t]
 \newsection{SECTION NAME}
 \subsection{Subsection Name}{\newsec: Title of Frame}

 Content
 \end{frame}
 \end{document}

For cross-section call, then a label is needed. All one needs to do is to do the following minor modifications.

 \makeatletter
 \newcommand\newsection[2]{%
 \section{#1}\label{#2}
 \@namedef{#2}{#1}
 }

 \newcommand\newsec[1]{% 
 \@nameuse{#1}
 }
 \makeatother

 \newsection{SECTION NAME}{tag}
 \subsection{Subsection Name}{\newsec{tag}: Title of Frame}

enter image description here

19

The beamer class offers macros such as \insertsection and \insertsubsection to access the current section’s name. They can be used in templates or manually.

\documentclass{beamer}

\begin{document}
\section{SECTION NAME}
\subsection{Subsection Name}
\begin{frame}{\insertsection: \insertsubsection}
    Content
\end{frame}
\end{document}

Search the manual for \insert to find more of these macros.

You must log in to answer this question.

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