Graphics, Figures & Tablesnewcommand or command in caption of figure?

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
formulation
Posts: 2
Joined: Thu Feb 03, 2011 4:49 pm

newcommand or command in caption of figure?

Post by formulation »

Dear all,

I have a graph which i need to explain in the caption. Unfortunately I need numbers and letters with a circle around in order to explain it (which is a scanned image). Therefore, I defined a new command in the preamble of the main document

\usepackage{tikz}
\newcommand*\mycirc[1]{%
\begin{tikzpicture}[baseline=(C.base)]
\node[draw,circle,inner sep=1pt](C) {#1};
\end{tikzpicture}}

and here the preview of the latex-code, I inserted the command via ERT:

\begin{figure}
\noindent \begin{centering}
\includegraphics[scale=0.5]{\string"../Pics/Chapter/1_\string".png}
\par\end{centering}
\caption{ diagram displaying the corrosion
\mycirc{1}\label{fig:1} }
\end{figure}


I cannot compile it, even when I insert the command directly into the caption, like

\begin{tikzpicture}[baseline=(C.base)] \node[draw,circle,inner sep=1pt](C) {1}; \end{tikzpicture}

it only produces errors, while both possible ways work outside the caption in standard environment.

Could anybody help me to get around that problem inside the caption environment?
thanks a lot and all the best!

Christoph

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
frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

newcommand or command in caption of figure?

Post by frabjous »

Try:

Code: Select all

\caption{ diagram displaying the corrosion
\protect\mycirc{1}\label{fig:1} }
If that doesn't work, then a proper minimal working example (rather than snippets) would be appreciated.
formulation
Posts: 2
Joined: Thu Feb 03, 2011 4:49 pm

Re: newcommand or command in caption of figure?

Post by formulation »

thank you a lot for your help, the \protect worked fine!
Next time I'll obey the guidelines you linked in your post.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

newcommand or command in caption of figure?

Post by localghost »

formulation wrote:[…] the \protect worked fine! […]
Then please mark the topic (not the last post) accordingly as written in the Section 3 of the Board Rules (to be read before posting).


Best regards and welcome to the board
Thorsten
Post Reply