Graphics, Figures & Tablesoverlapped symbols in figure caption

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
CoolnessItself
Posts: 47
Joined: Wed Nov 11, 2009 9:30 pm

overlapped symbols in figure caption

Post by CoolnessItself »

Using stackrel and stackinset in a figure caption results in the error
! Argument of \@caption has an extra }.
<inserted text>
\par
l.19 ... these two symbols to overlap $\overlap$.}
Am I missing something?

mwe:

Code: Select all

\documentclass{article}

\usepackage{stackengine,scalerel}

\def\useanchorwidth{F}
\def\stackalignment{r}%
\newcommand\overlap{\scalerel*{\hspace{.5mm}\stackinset{c}{-1.5pt}{c}{}{$O$}{$L$}}{+}}

\begin{document}

%works if this is the only \overlap in the document
This is some text with the $\overlap$ symbols.

\begin{figure}[t]
\begin{center}
figure
\end{center}
\caption{I want these two symbols to overlap $\overlap$.} %doesn't work
\end{figure}


\end{document}

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

User avatar
sommerfee
Posts: 503
Joined: Mon Apr 09, 2007 4:20 pm

overlapped symbols in figure caption

Post by sommerfee »

The command \overlap you have defined is fragile and therefore will not be handled correctly in moving arguments like entries for List of Contents or List of Figure. So either make \overlap robust:

Code: Select all

\DeclareRobustCommand\overlap{\scalerel*{...}{+}}
or use \protect for usage of \overlap within moving arguments:

Code: Select all

\section{...\protect\overlap...}

Code: Select all

\caption{...\protect\overlap...}
CoolnessItself
Posts: 47
Joined: Wed Nov 11, 2009 9:30 pm

Re: overlapped symbols in figure caption

Post by CoolnessItself »

Thanks! I'm not familiar with fragile commands. How can I tell if I'm constructing something fragile? Is it the command I'm declaring or its substitute, i.e., is \newcommand\overlap{} the issue or what's inside the fragile part?
Post Reply