Tell me more ×
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 wish to create tikzpicture environments inside a node of another tikzpicture. The problem I encouter is that styles are inherited by the inner tikzpicture. How can I screen of the inner tikzpicture form the outer one? Or is this impossible?

The following minimal example illustrates the problem:

\documentclass{minimal}
\usepackage{tikz}
  \usetikzlibrary{positioning}
\begin{document}

% wanted: square centered on line
\begin{tikzpicture}
  \draw (0,0) -- (0,1);
  \node[fill] at (0,.5) {};
\end{tikzpicture}

% got: square to the right of line
\begin{tikzpicture}[red]
  \node[fill] (O) {};
  \node[right=of O] {% <- this 'right of' is inherited; how to avoid?
  \begin{tikzpicture}
    \draw (0,0) -- (0,1);
    \node[fill] at (0,.5) {};
  \end{tikzpicture}
  };
\end{tikzpicture}

\end{document}
share|improve this question
right of is not inherited but it's right= of Make a try with right of= O – Alain Matthes Mar 9 '12 at 11:19

1 Answer

up vote 7 down vote accepted

In this specific case you can use anchor=center to restore the default positioning. The right etc. settings modify the used anchor.

\documentclass{minimal}
\usepackage{tikz}
  \usetikzlibrary{positioning}
\begin{document}

% wanted: square centered on line
\begin{tikzpicture}
  \draw (0,0) -- (0,1);
  \node[fill] at (0,.5) {};
\end{tikzpicture}

% got: square to the right of line
\begin{tikzpicture}[red]
  \node[fill] (O) {};
  \node[right=of O] {% <- this 'right of' is inherited; how to avoid?
  \begin{tikzpicture}[anchor=center]
    \draw (0,0) -- (0,1);
    \node[fill] at (0,.5) {};
  \end{tikzpicture}
  };
\end{tikzpicture}

\end{document}

In the general case if you want to avoid any settings to affect the sub-tikzpicture I would store it into a savebox before the main tikzpicture and insert that box:

\documentclass{minimal}
\usepackage{tikz}
  \usetikzlibrary{positioning}
\begin{document}

% wanted: square centered on line
\begin{tikzpicture}
  \draw (0,0) -- (0,1);
  \node[fill] at (0,.5) {};
\end{tikzpicture}


\newsavebox\mybox

\begin{lrbox}{\mybox}
  \begin{tikzpicture}
    \draw (0,0) -- (0,1);
    \node[fill] at (0,.5) {};
  \end{tikzpicture}
\end{lrbox}

% got: square to the right of line
\begin{tikzpicture}[red]
  \node[fill] (O) {};
  \node[right=of O] {% <- this 'right of' is inherited; how to avoid?
        \usebox\mybox
  };
\end{tikzpicture}

\end{document}
share|improve this answer
So there's no command to reset all TikZ attributes to default in this case? – krlmlr Feb 8 '12 at 8:49
1  
@user946850: No, I don't think so. Such a command would be very difficult to maintain, because all TikZ attributes would need need to be set with it explicitly. You can't reset things in TeX only overwrite them (with the exception of grouping of course). – Martin Scharrer Feb 8 '12 at 10:45
Thanks, that's what I feared. – krlmlr Feb 8 '12 at 20:51

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.