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\CircleTextbut 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
\useboxas 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
tikxpicturewhich 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\nodewithin a\nodewhich 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}


tikzpictures, 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. – cfr Mar 21 '18 at 04:04tikz. – Peter Grill Mar 21 '18 at 04:06tikzmarkwould be useful to look at as, if I'm remembering correctly, it does something like this. – cfr Mar 21 '18 at 04:08tikzmarkdoes it or in some other way. Probably all you need is to tack a toggle switch onto the start of pictures to set a conditional true or false. However, probably there is something you can test already without the need to do this. – cfr Mar 21 '18 at 04:13tikzpicturehow would I define\CircleTextwithout anode? Is a\nodewithin a\nodeok? – Peter Grill Mar 21 '18 at 04:16tikzmarksupplies a different macro for that case, so you'd need something more analogous to\subnode. – cfr Mar 21 '18 at 04:36tikzsymbolspackage. They can be used even inside nodes inside pictures because they get saved to boxes. (At least, I think that's why.) – cfr Mar 21 '18 at 04:40tikzmarktakes and the answer which you got. – cfr Mar 22 '18 at 00:02