我在将四张 TikZ 图片放在一张图中时遇到了问题。我使用 subfigure 嵌入 TikZ 图片。现在我遇到了以下问题:我不知道如何缩放 TikZ 图形。当我使用resizebox
或 时scale
,看起来一张 TikZ 图片的缩放也应用于下一张 TikZ 图形(见下图)。
这是我的代码:
\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}
\结束{文档}
结果如下:
答案1
此问题是由使用的线路引起的
\node[state] (D) [below right of = D, style={dashed}, label=above:$N_{c1}$] {$\boldsymbol{4}$};
您将 放置D
在其自身的右下方。节点是全局的,tikzpicture
因此后面的 重用了D
之前图片中 的旧位置,导致它越来越向右下方移动。这实际上导致Package pgf Error: No shape named D is known.
第一张图片出现 ,这应该让你产生怀疑。我认为您的意思是并且想要的是below right of = C
。然后它可以与 配合使用\resizebox
。
对于复杂内容的缩放,我还推荐adjustbox
提供 的包\adjustbox{<includegraphics options>}{<content>}
,它不会将内容读取为宏参数,而是读取为框。你在这里需要\adjustbox{width=.4\textwidth}{ ... }
。
\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}