6

I do use the \substack-command in text for creating a small (2,1)-Vector. Unfortunately it does not work in the title of a section.

Here a minimal example, which does not work:

\documentclass{scrreprt}
\usepackage{amsmath}
\begin{document}
\section{$\substack{ a\\b }$}
\end{document}

To my surprise it works, if I use \section* instead of \section. I am far from understanding enough about TeX to tell why this happens, but can anyone give me an advise how I can fix it?

PS: I also tried to substitute \substack by smallmatrix, which did work for the first two times I compiled the file. After the third compilation I got the same problems.

EDIT: The Problem was solved, using the \protect-command. But now I want to use the same sectiontitle for a beamer presentation, using the beamer-class. Also using the \protect-command I receive an error. How can I solve this?

6

1 Answer 1

7

\substack is what is known as a fragile command in LaTex and needs protecting in situations like section titles and captions that get written to external files for producing tables of contents etc. See What is the difference between Fragile and Robust commands? for some more information on fragile commands.

Sample output

\documentclass{scrreprt}

\usepackage{amsmath}

\begin{document}
\tableofcontents

\section{$\protect\substack{ a\\b }$}

\end{document}

If you have the hyperref package loaded then you will also need to provide a plain text version, via

\section{\texorpdfstring{$\protect\substack{ a\\b }$}{a/b}}

Finally, if using the beamer class there is an extra problem with \\ which beamer redefines. One work around in this case is to define a custom command to be used in the title:

\documentclass{beamer}

\usetheme{Warsaw}

\usepackage{amsmath}
\DeclareRobustCommand{\myfr}{\texorpdfstring{$\substack{a\\b}$}{a/b}}

\begin{document}

\section{\myfr}

\begin{frame}
  Test.
\end{frame}
\end{document}

Notice here that you can make the command robust from the start.

Beamer sample

1
  • Thx, for this Extension. Using the \textorpdfstring-command, I can now solve all my problems.
    – Greyfox
    Apr 14, 2013 at 19:42

You must log in to answer this question.

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