# How to place and scale TikZ pictures in subfigure?

I have a problem with placing four TikZ pictures in one figure. I use subfigure to embedded TikZ pictures. Now I have the following problem: I do not know how to scale the TikZ figures. When I use resizebox or scale, it looks like the scaling from one TikZ picture is applied also to next TikZ figures (see the picture below).

Here is my code:

\documentclass{article}

\usepackage{subfigure}
\usepackage{pgf}
\usepackage{tikz}
\usepackage{pgf}

%zusaetzlihce Symbole und Schriften (ams: american mathematical soc)
\usepackage{amssymb}
\usepackage{amstext}
\usepackage{amsfonts}
\usepackage{amsbsy}
\usepackage{amscd}
\usepackage{latexsym}

\begin{document}
\usetikzlibrary{arrows,automata}
\begin{figure}[htbp]

\begin{tabular}{cc}
%%%%%%%%%%%%%%%%%%%%%% 1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subfigure [Subfigure 1] {
\resizebox{0.4\textwidth}{!}{%
\begin{tikzpicture}[->,>=stealth',shorten >=2pt,node distance=2.0cm,
semithick] %,scale=.5]
\tikzstyle{every state}=[fill=white,draw=black,text=black,font=\small]

\node[state] (A) [label=above:$N_{f1}$]                                            {$1$};
\node[state] (B) [below left  of = A,     label=above:$N_{a1}$]    {$\boldsymbol{2}$};
\node[state] (C) [below right of = A ,  label=above:$N_{b1}$]      {$\boldsymbol{3}$};
\node[state] (D) [below right of = D, style={dashed}, label=above:$N_{c1}$]      {$\boldsymbol{4}$};

\path (B) edge []       node {} (A)
(C) edge []             node {} (A)
(D) edge []       node {} (C)
;

\end{tikzpicture}
}
} &
%%%%%%%%%%%%%%%%%%%%%% 2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subfigure [Subfigure 2] {
%\resizebox{0.4\textwidth}{!}{%
\begin{tikzpicture}[->,>=stealth',shorten >=2pt,node distance=2.0cm,
semithick] % ,scale=.5]
\tikzstyle{every state}=[fill=white,draw=black,text=black,font=\small]

\node[state] (A) [label=above:$N_{f\_1}$]                                          {$1$};
\node[state] (B) [below left  of = A,     label=above:$N_{a1}$]    {$\boldsymbol{2}$};
\node[state] (C) [below right of = A , style={dashed},  label=above:$N_{b1}$]      {$\boldsymbol{3}$};
\node[state] (D) [below right of = D,  label=above:$N_{c_1}$]    {$\boldsymbol{4}$};

\path (B) edge []       node {} (A)
(C) edge []             node {} (A)
(D) edge []       node {} (C)
;
\end{tikzpicture}
%}
} \\

%%%%%%%%%%%%%%%%%%%%%% 3 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subfigure [Subfigure 3] {
% \resizebox{0.4\textwidth}{!}{%
\begin{tikzpicture}[->,>=stealth',shorten >=2pt,node distance=2.0cm,
semithick] %,scale=.5]
\tikzstyle{every state}=[fill=white,draw=black,text=black,font=\small]

\node[state] (A) [                     label=above:$N_{f\_1}$, , style={dashed}]                                           {$1$};
\node[state] (B) [below left  of = A,  label=above:$N_{a1}$]   {$\boldsymbol{2}$};
\node[state] (C) [below right of = A,  label=above:$N_{b1}$]   {$\boldsymbol{3}$};
\node[state] (D) [below right of = D,  label=above:$N_{c_1}$]    {$\boldsymbol{4}$};

\path (B) edge []       node {} (A)
(C) edge []             node {} (A)
(D) edge []       node {} (C)
;

\end{tikzpicture}
%   }
} &

%%%%%%%%%%%%%%%%%%%%%% 4 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subfigure [Subfigure 4] {
% \resizebox{0.4\textwidth}{!}{%
\begin{tikzpicture}[->,>=stealth',shorten >=2pt,node distance=2.0cm,
semithick] % ,scale=.5]
\tikzstyle{every state}=[fill=white,draw=black,text=black,font=\small]

\node[state] (A) [                                            label=above:$N_{f\_1}$]                                          {$1$};
\node[state] (B) [below left  of = A,     label=above:$N_{a1}$, style={dashed}]    {$\boldsymbol{2}$};
\node[state] (C) [below right of = A ,  label=above:$N_{b1}$, style={dashed}]      {$\boldsymbol{3}$};
\node[state] (D) [below right of = D,   label=above:$N_{c_1}$]   {$\boldsymbol{4}$};

\path (B) edge []       node {} (A)
(C) edge []             node {} (A)
(D) edge []       node {} (C)
;

\end{tikzpicture}
%}
} \\
\end{tabular}
\caption{Several options}
\end{figure}


\end{document}

Here is the result:

-
Please modify your code so to have a minimal working example (adding also all necessary packages). –  Marco Lombardi Jun 1 '11 at 13:56
This does not concerne your problem, but the package subfigure is obsolete. Use subfig instead. –  Spike Jun 1 '11 at 14:54

The issue is caused by the used line

\node[state] (D) [below right of = D, style={dashed}, label=above:$N_{c1}$]      {$\boldsymbol{4}$};


You are placing D below right of itself. Nodes are global and the later tikzpictures therefore reuse the old position of D from the previous pictures, causing it to move more and more to the bottom right. This actually causes an Package pgf Error: No shape named D is known. for the first picture, which should have made you suspicious. I think what you meant and want is below right of = C instead. Then it works fine with \resizebox.
For scaling of complex contents I would also recommend the adjustbox package which provides \adjustbox{<includegraphics options>}{<content>} which doesn't read the content as macro argument but as box. You would need \adjustbox{width=.4\textwidth}{ ... } here.

\documentclass{article}

\usepackage{tikz}
\usepackage{subfigure}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{array}
\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}

\usetikzlibrary{arrows,automata}

\begin{document}

\begin{figure}[htbp]

\begin{tabular}{C{.48\textwidth}C{.48\textwidth}}
%%%%%%%%%%%%%%%%%%%%%% 1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subfigure [Subfigure 1] {
\resizebox{0.4\textwidth}{!}{%
\begin{tikzpicture}[->,>=stealth',shorten >=2pt,node distance=2.0cm,
semithick] %,scale=.5]
\tikzstyle{every state}=[fill=white,draw=black,text=black,font=\small]

\node[state] (A) [label=above:$N_{f1}$]                                            {$1$};
\node[state] (B) [below left  of = A,     label=above:$N_{a1}$]    {$\boldsymbol{2}$};
\node[state] (C) [below right of = A ,  label=above:$N_{b1}$]      {$\boldsymbol{3}$};
\node[state] (D) [below right of = C, style={dashed}, label=above:$N_{c1}$]      {$\boldsymbol{4}$};

\path (B) edge []       node {} (A)
(C) edge []             node {} (A)
(D) edge []       node {} (C)
;

\end{tikzpicture}
}
} &
%%%%%%%%%%%%%%%%%%%%%% 2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subfigure [Subfigure 2] {
\resizebox{0.4\textwidth}{!}{%
\begin{tikzpicture}[->,>=stealth',shorten >=2pt,node distance=2.0cm,
semithick] % ,scale=.5]
\tikzstyle{every state}=[fill=white,draw=black,text=black,font=\small]

\node[state] (A) [label=above:$N_{f\_1}$]                                          {$1$};
\node[state] (B) [below left  of = A,     label=above:$N_{a1}$]    {$\boldsymbol{2}$};
\node[state] (C) [below right of = A , style={dashed},  label=above:$N_{b1}$]      {$\boldsymbol{3}$};
\node[state] (D) [below right of = C,  label=above:$N_{c_1}$]    {$\boldsymbol{4}$};

\path (B) edge []       node {} (A)
(C) edge []             node {} (A)
(D) edge []       node {} (C)
;
\end{tikzpicture}
}
} \\

%%%%%%%%%%%%%%%%%%%%%% 3 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subfigure [Subfigure 3] {
\resizebox{0.4\textwidth}{!}{%
\begin{tikzpicture}[->,>=stealth',shorten >=2pt,node distance=2.0cm,
semithick] %,scale=.5]
\tikzstyle{every state}=[fill=white,draw=black,text=black,font=\small]

\node[state] (A) [                     label=above:$N_{f\_1}$, , style={dashed}]                                           {$1$};
\node[state] (B) [below left  of = A,  label=above:$N_{a1}$]   {$\boldsymbol{2}$};
\node[state] (C) [below right of = A,  label=above:$N_{b1}$]   {$\boldsymbol{3}$};
\node[state] (D) [below right of = C,  label=above:$N_{c_1}$]    {$\boldsymbol{4}$};

\path (B) edge []       node {} (A)
(C) edge []             node {} (A)
(D) edge []       node {} (C)
;

\end{tikzpicture}
}
} &

%%%%%%%%%%%%%%%%%%%%%% 4 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subfigure [Subfigure 4] {
\resizebox{0.4\textwidth}{!}{%
\begin{tikzpicture}[->,>=stealth',shorten >=2pt,node distance=2.0cm,
semithick] % ,scale=.5]
\tikzstyle{every state}=[fill=white,draw=black,text=black,font=\small]

\node[state] (A) [                                            label=above:$N_{f\_1}$]                                          {$1$};
\node[state] (B) [below left  of = A,     label=above:$N_{a1}$, style={dashed}]    {$\boldsymbol{2}$};
\node[state] (C) [below right of = A ,  label=above:$N_{b1}$, style={dashed}]      {$\boldsymbol{3}$};
\node[state] (D) [below right of = C,   label=above:$N_{c_1}$]   {$\boldsymbol{4}$};

\path (B) edge []       node {} (A)
(C) edge []             node {} (A)
(D) edge []       node {} (C)
;

\end{tikzpicture}
}
} \\
\end{tabular}
\caption{Several options}
\end{figure}

\end{document}


-