LaTeX forum ⇒ Presentations and Posters ⇒ Customized frame title with examples and how to reference those examples? Topic is solved

Beamer, Powerdot and KOMA-Script presentations, Conference posters (a0poster, baposter, tikzposter)
CMP
Posts: 6
Joined: Thu Aug 22, 2019 8:33 pm

Customized frame title with examples and how to reference those examples?

I am trying to create examples on the LaTeX Beamer frame title, count them and reference them in the other frame title. By googling, I was able to count the examples but not able to reference it in the next slide in the title.

So, I am wondering if there is any sort of idea to achieve this goal.

Here is the minimal working example and the issue is mentioned on the last slide, too.

I also post the same question here,
https://tex.stackexchange.com/questions ... e-examples.

\documentclass[xcolor=dvipsnames]{beamer}\usepackage[T1]{fontenc}\usetheme{AnnArbor}\usecolortheme{whale}\setbeamercolor{title}{bg=RoyalPurple}\setbeamercolor{frametitle}{fg=white,bg=RoyalPurple}\usepackage{amsmath}\newcounter{exm}\newcommand\ExmT{%\frametitle{\refstepcounter{exm}{Example}~\theexm}}\resetcounteronoverlays{exm}\begin{document}\frame{\ExmTDavid Hilbert is a great Mathematician!}\frame{\ExmTBernhard Riemann is another greatest mathematician in the history!}\frame{{How do you define Mathematics?}Mathematics is a language of sciences. Moreover, $\cdots$}\frame{{Rmarks on Example 1}{\color{red}\textbf{I am writing Remarks on Example 1 (on the title of this frame) manually but is there a way to reference Example 1 automatically?}} Not the frame number.}\end{document}

Thanks to the LaTeX community.

Ijon Tichy
Posts: 119
Joined: Mon Dec 24, 2018 10:12 am
To reference the example number you need to put a label inside the group of the corresponding \refstepcounter. This can be done using an optional argument to \ExmT. To reference not only the number but the title, you need to setup \@currentlabelname before the \label.
\documentclass[xcolor=dvipsnames]{beamer}\usepackage[T1]{fontenc}\usetheme{AnnArbor}\usecolortheme{whale}\setbeamercolor{title}{bg=RoyalPurple}\setbeamercolor{frametitle}{fg=white,bg=RoyalPurple} \usepackage{amsmath} \newcounter{exm}\makeatletter\newcommand\ExmT[1][]{%  \frametitle{%    \refstepcounter{exm}%    \ifx\relax#1\relax\else      \edef\@currentlabelname{Example~\theexm}%      \label{#1}%    \fi    Example~\theexm}%}\makeatother\resetcounteronoverlays{exm} \begin{document} \frame{%  \frametitle{Testframe}  To avoid that exmaples and frames have the same number.} \frame{\ExmT[ex:hilbert]%David Hilbert is a great Mathematician!} \frame{\ExmT[ex:riemann]%Bernhard Riemann is another greatest mathematician in the history! } \frame{{How do you define Mathematics?} Mathematics is a language of sciences. Moreover, $\cdots$ } \frame{{Rmarks on \nameref{ex:hilbert}} {\color{red}\textbf{I am writing Remarks on Example~\ref{ex:hilbert} on    page~\pageref{ex:hilbert} (on the title of this frame) manually but is there a way to reference \nameref{ex:hilbert} automatically?}} Not the frame number.}  \end{document}

But IMHO it would be better to do the \refstepcounter outside \frametitle. In this case, you can add the \label behind the \ExmT command as usual:
\documentclass[xcolor=dvipsnames]{beamer}\usepackage[T1]{fontenc}\usetheme{AnnArbor}\usecolortheme{whale}\setbeamercolor{title}{bg=RoyalPurple}\setbeamercolor{frametitle}{fg=white,bg=RoyalPurple} \usepackage{amsmath} \newcounter{exm}\makeatletter\newcommand\ExmT{%  \refstepcounter{exm}%  \protected@edef\@currentlabelname{Example\protect~\theexm}%  \frametitle{%    Example~\theexm}%}\makeatother\resetcounteronoverlays{exm} \begin{document} \frame{%  \frametitle{Testframe}  To avoid that exmaples and frames have the same number.} \frame{\ExmT\label{ex:hilbert}%David Hilbert is a great Mathematician!} \frame{\ExmT\label{ex:riemann}%Bernhard Riemann is another greatest mathematician in the history! } \frame{{How do you define Mathematics?} Mathematics is a language of sciences. Moreover, $\cdots$ } \frame{{Rmarks on \nameref{ex:hilbert}} {\color{red}\textbf{I am writing Remarks on Example~\ref{ex:hilbert} on    page~\pageref{ex:hilbert} (on the title of this frame) manually but is there a way to reference \nameref{ex:hilbert} automatically?}} Not the frame number.}  \end{document}

CMP
Posts: 6
Joined: Thu Aug 22, 2019 8:33 pm
It works perfectly well to my need.

Thank you very much, Ijon Tichy!

CMP
Posts: 6
Joined: Thu Aug 22, 2019 8:33 pm
It works perfectly well to my need.

Thank you very much, Ijon Tichy!

CMP
Posts: 6
Joined: Thu Aug 22, 2019 8:33 pm
I am also wondering whether we could assign hyperref with some specified color?

Thank you!

CMP
Posts: 6
Joined: Thu Aug 22, 2019 8:33 pm
I am also wondering how to adjust the example with title. For example,

Example 17: Who is Hilbert?

on the frame title.Ijon Tichy

Ijon Tichy
Posts: 119
Joined: Mon Dec 24, 2018 10:12 am
In this case you have to define your command with an argument, that is passed to \frametitle, e.g.:
    \documentclass[xcolor=dvipsnames]{beamer}    \usepackage[T1]{fontenc}    \usetheme{AnnArbor}    \usecolortheme{whale}    \setbeamercolor{title}{bg=RoyalPurple}    \setbeamercolor{frametitle}{fg=white,bg=RoyalPurple}     \usepackage{amsmath}     \newcounter{exm}    \makeatletter    \newcommand*{\ExmT}[1]{%      \refstepcounter{exm}%      \protected@edef\@currentlabelname{Example\protect~\theexm: #1}%      \frametitle{%        Example~\theexm: #1}%    }    \makeatother    \resetcounteronoverlays{exm}     \begin{document}     \frame{%      \frametitle{Testframe}      To avoid that exmaples and frames have the same number.    }     \frame{    \ExmT{Who is Hilbert}\label{ex:hilbert}%    David Hilbert is a great Mathematician!    }     \frame{    \ExmT{Who is Riemann}\label{ex:riemann}%    Bernhard Riemann is another greatest mathematician in the history!     }     \frame{{How do you define Mathematics?}     Mathematics is a language of sciences. Moreover, $\cdots$     }     \frame{{Rmarks on \nameref{ex:hilbert}}     {\color{red}\textbf{I am writing Remarks on Example~\ref{ex:hilbert} on        page~\pageref{ex:hilbert} (on the title of this frame) manually but is there a way to reference \nameref{ex:hilbert} automatically?}} Not the frame number.    }      \end{document}

If you want some examples with title and some without, you need either two different commands or (once again) an optional argument. See a LaTeX introduction about how to define commands with optional arguments.

BTW: I would recommend to use the frame environment with LaTeX. The command \frame is supported for legacy documents only. See the footnote in section 8.1 of the beamer manual.

Note, I usually do not read answered questions. So if you have a following up question it would be better to ask a new one (with link to the initial question/answer if useful).