Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm nesting a tikzpicture inside a tikzpicture, and having problems with the 'text width' parameter leaking through from the outer tikzpicture to the inner. (The nesting is pretty much unavoidable -- in my actual use case the tikzpicture s are defined in different macros.)

MWE:

\documentclass[a4paper,11pt,landscape]{article}
\usepackage{tikz,nopageno}

\begin{document}

\newcommand{\cost}{%
\begin{tikzpicture}
    \node[fill=red!85!black,shape=circle,inner sep=0.3mm,draw=black,text=white] {\raisebox{0pt}[\height][0pt]{\bf 1}};
\end{tikzpicture}}

\cost

\begin{tikzpicture}
    \node[text width=10mm] {\cost};
\end{tikzpicture}

\end{document}

enter image description here

How should I modify 'cost' so that it behaves as if text width was not set?

share|improve this question

1 Answer 1

up vote 4 down vote accepted

Package tikz maps the value of key text width to the macro content of \tikz@text@width. The default is empty, thus you can reset the key text width by option setting text width={}:

\documentclass[a4paper,11pt,landscape]{article}
\usepackage{tikz,nopageno}

\begin{document}

\newcommand{\cost}{%
  \begin{tikzpicture}
    \node[
      text width={},
      text height={}, % dito
      fill=red!85!black,
      shape=circle,
      inner sep=0.3mm,
      draw=black,
      text=white,
    ] {\raisebox{0pt}[\height][0pt]{\bf 1}};
  \end{tikzpicture}%
}

\cost

\begin{tikzpicture}
  \node[text width=10mm] {\cost};
\end{tikzpicture}

\end{document}

Result

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.