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 want to use dash rectangle in outer node but use solid rectangle in inner nodes. But my sample code below actually dashed all node for inner or outer nodes.

\documentclass[tikz]{standalone}

\begin{document}

\begin{tikzpicture}[
  inner/.style={draw,fill=blue!5,thick,inner sep=3pt,minimum width=8em},
  outer/.style={draw=gray,dashed,fill=green!1,thick,inner sep=5pt}
  ]
%---------------------------------------------------%
\node[outer] (A) {
    \begin{tikzpicture}[node distance=1cm,outer sep = 0pt]
      \node [inner,minimum width=18em] (A1) {Mr. A};
      \node [inner,anchor=south west,minimum width=8em] (A2) at ([yshift=1em]A1.north west) {Mr. A1};
      \node [inner,anchor=south east,minimum width=8em] (A3) at ([yshift=1em]A1.north east) {Mr. A2};
      \node (text) [anchor=north] at ([yshift=4em]A1.north) {Hello Tikz};
    \end{tikzpicture}
}; 
\end{tikzpicture}

\end{document} 

The output looks like below:

enter image description here

I only use dashed on outer style but actually inner nodes has got such attribute also! I don't want that!

share|improve this question
2  
Nesting tikz pictures is almost always a bad idea as you can see here. All settings are inherited etc. Use the fit library instead –  percusse Aug 20 at 20:02

2 Answers 2

up vote 4 down vote accepted

Using fit and backgrounds for avoiding nested tikzpicture. The Zarko's answer is easier than mine but i wanted to illustrate this option. It can be useful in other contexts.

\documentclass[tikz]{standalone}
\usetikzlibrary{fit,backgrounds} % <- added
\begin{document}

\begin{tikzpicture}[
  inner/.style={draw,fill=blue!5,thick,inner sep=3pt,minimum width=8em},
  outer/.style={draw=gray,dashed,fill=green!1,thick,inner sep=5pt}
  ]
%---------------------------------------------------%
  \node [inner,minimum width=18em] (A1) {Mr. A};
  \node [inner,anchor=south west,minimum width=8em] (A2) at ([yshift=1em]A1.north west) {Mr. A1};
  \node [inner,anchor=south east,minimum width=8em] (A3) at ([yshift=1em]A1.north east) {Mr. A2};
  \node (text) [anchor=north] at ([yshift=4em]A1.north) {Hello Tikz};
\begin{pgfonlayer}{background}
\node[outer,fit=(A1) (A2) (A3) (text)] (A) {};
\end{pgfonlayer}
\end{tikzpicture}

\end{document} 

The result is the same.

share|improve this answer
    
Cool, but if I want to use multiple group such things, I wish to treat it as a group for positioning, how can I group this version as one? such as it maybe better to use "below=1cm of A" of B group. –  Beatlej Aug 20 at 21:23
1  
your group is in reality a referenced node with label (A), so you can use "below=1cm of A" whenever you load the positioning library. –  skpblack Aug 20 at 21:45

Try:

\documentclass[tikz]{standalone}
\begin{document}
    \begin{tikzpicture}[
inner/.style={draw,
              solid,% <-- added
              fill=blue!5,thick,inner sep=3pt,minimum width=8em},
outer/.style={draw=gray,dashed,fill=green!1,thick,inner sep=5pt}
                        ]
\node[outer] (A) {
    \begin{tikzpicture}[node distance=1cm,outer sep = 0pt]
      \node [inner,minimum width=18em] (A1) {Mr. A};
      \node [inner,anchor=south west,minimum width=8em] (A2) at ([yshift=1em]A1.north west) {Mr. A1};
      \node [inner,anchor=south east,minimum width=8em] (A3) at ([yshift=1em]A1.north east) {Mr. A2};
      \node (text) [anchor=north] at ([yshift=4em]A1.north) {Hello Tikz};
    \end{tikzpicture}
                };
    \end{tikzpicture}
\end{document} 
share|improve this answer
    
Good suggestion, that means it has been override actually, but maybe some other things need to rewrite also. do we have method to prevent such heritage? –  Beatlej Aug 20 at 21:26
1  
In nested TikZ pictures the parameters of outside picture always influence on inside picture. Some times you can help yourself with trick as I show you in my answer, but generally the better approach is given in second answer. –  Zarko Aug 20 at 23:49

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.