When I use the \CircleText
macro within a \node
in which the text width=
is specified, the text width=
gets applied to \CircleText
. Is there a way to reset the style so that \CircleText
does not inhert the text width=
style. The MWE below produces:
I think, if at the start of the options to \CircleText
, I could somehow reset all style to their default setting, this would work fine.
Notes:
- One solution would be to set the
text width=
to something appropriate within\CircleText
but all that does is deffer this problem until there is some other style that I do not want to be inherited. - Another solution would be to create boxes for each numnber and then use
\usebox
as suggested at Proper nesting of tikzpicture environments: Reset all PGF values to their defaults. - It has been pointed out in the comments that this is a case of a nested
tikxpicture
which is not officially supported and could break at any time. This can easily be remedied with the solution provided at Is there a (simple) way to find out if a command is executed in a tikzpicture environment?. However, this then requires the use of a\node
within a\node
which does not even compile.
Code:
\documentclass{article}
\usepackage{tikz}
%% https://tex.stackexchange.com/questions/15334/getting-numbers-to-appear-in-circles
\newcommand*{\CircledText}[2][fill=red!40]{%
\tikz[baseline=(char.base)]{%
\node[
shape=circle,
draw=black, thick,
fill opacity=0.3,
text opacity=1,
inner sep=0.8pt,
outer sep=0pt,
#1
] (char) {#2};}%
}%
\newcommand*{\DesiredText}{\CircledText{3} Some text}
\begin{document}
Outside of tikzpicture: \DesiredText
\bigskip
Inside of tikzpicture \emph{without} ``text width='' specified):
\begin{tikzpicture}
\node at (4,0) {\DesiredText};
\end{tikzpicture}
\bigskip
Inside of tikzpicture \emph{with} ``text width='' specified):
\begin{tikzpicture}
\node [text width=5.0cm] at (4,0) {\DesiredText};
\end{tikzpicture}
\end{document}
tikzpicture
s, which isn't supported and would be liable to break at any time even if it happened to work in some particular case? I assume I'm missing something, because obviously you know this as well as I do.tikz
.tikzmark
would be useful to look at as, if I'm remembering correctly, it does something like this.