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 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
    
A while after asking this question, I put the tikzpictures that I want to put in nodes in TeX boxes; cf. tex.stackexchange.com/a/66028/87. An approach which I feel is more convenient. –  equaeghe Jul 16 '13 at 14:18
    
Yes it's a fine possibility. I use it in some cases but you can imagine the possibility to pass some arguments between the two tikzpictures. I think it's not possible with a TeX box but I'm not sure. In a general case, the TeX box is a good approach. –  Alain Matthes Jul 16 '13 at 20:05
add comment

1 Answer

up vote 10 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
add comment

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.