这就是我需要的:
这是我刚刚得到的结果:
\documentclass[border = 2pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{automata,positioning,fit}
\begin{document}
\begin{tikzpicture}
\node[] (B) at (0,1) {B};
\node[state, initial text=, initial below, accepting] (initial) {\textbf{0}};
\node[right=of initial.south, yshift=-5mm, xshift=3mm] (B1) {
\begin{tikzpicture}
\node[state] (10) {$b_{10}$};
\node[state] (11) [below=of 10] {$b_{11}$};
\begin{scope}[every node/.style={scale=.7}]
\path[->]
(10) edge [bend right] node {$\beta_{11}$} (11)
(11) edge [bend right] node {$\alpha_{21}$} (10);
\end{scope}
\end{tikzpicture}};
\node[right=of B1, yshift=-0mm] (B2) {
\begin{tikzpicture}
\node[state] (20) {$b_{20}$};
\node[state] (21) [below=of 20] {$b_{21}$};
\begin{scope}[every node/.style={scale=.7}]
\path[->]
(20) edge [bend right] node {$\beta_{21}$} (21)
(21) edge [bend right] node {$\alpha_{22}$} (20);
\end{scope}
\end{tikzpicture}};
\node[draw,dashed,fit=(B1)] {};
\node[draw,dashed,fit=(B2)] {};
\node[draw,fit=(B)(B1)(B2), inner sep=3mm] {};
\end{tikzpicture}
\end{document}
我无法处理红色边缘remember picture
建议处理红色边缘这里。
此外,[swap]
以下说法也不起作用:
(21) edge [bend right] node[swap] {$\alpha_{22}$} (20);
更新 :
根据@cfr的建议,我使用不同的方法设计了草图savebox/usebox
,而不是嵌套的tikzpictures,如下所示:
\documentclass[border = 2pt]{standalone}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{automata,positioning,fit}
\newsavebox\BB
\savebox{\BB}{
\begin{tikzpicture}
\node[state] (10) {$b_{10}$};
\node[state] (11) [below=of 10] {$b_{11}$};
\begin{scope}[every node/.style={scale=.7}]
\path[->]
(10) edge [bend right] node {$\beta_{11}$} (11)
(11) edge [bend right] node {$\alpha_{21}$} (10);
\end{scope}
\end{tikzpicture}}
\newsavebox\CC
\savebox{\CC}{
\begin{tikzpicture}
\node[state] (20) {$b_{20}$};
\node[state] (21) [below=of 20] {$b_{21}$};
\begin{scope}[every node/.style={scale=.7}]
\path[->]
(20) edge [bend right] node {$\beta_{21}$} (21)
(21) edge [bend right] node {$\alpha_{22}$} (20);
\end{scope}
\end{tikzpicture}}
\begin{document}
\begin{tikzpicture}
\node[] (B) at (0,1) {B};
\node[state, initial text=, initial below, accepting] (initial) {\textbf{0}};
\node[right=of initial.south, yshift=-5mm, xshift=3mm] (B1) {
\usebox{\BB}};
\node[right=of B1, yshift=-0mm] (B2) {
\usebox{\CC}};
\node[draw,dashed,fit=(B1)] {};
\node[draw,dashed,fit=(B2)] {};
\node[draw,fit=(B)(B1)(B2), inner sep=3mm] {};
\end{tikzpicture}
\end{document}
答案1
永远不要嵌套tikzpicture
环境。在简单的情况下,如果你幸运的话,它可能会起作用,但它不受支持,如果它后来坏了,你只能保留所有微小的碎片。
但是,作用域可以以类似的方式使用。例如,
\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{automata,positioning,fit,quotes}
\begin{document}
\begin{tikzpicture}
\node[] (B) at (0,1) {B};
\node[state, initial text=, initial below, accepting] (initial) {\textbf{0}};
\begin{scope}[local bounding box=B1, shift=(initial.west), xshift=25mm]
\node[state] (10) {$b_{10}$};
\node[state] (11) [below=of 10] {$b_{11}$};
\begin{scope}[every node/.style={scale=.7}]
\path[->]
(10) edge [bend right] node [left] {$\beta_{11}$} (11)
(11) edge [bend right] node [right] {$\alpha_{21}$} (10);
\end{scope}
\end{scope}
\begin{scope}[local bounding box=B2, shift=(B1.west |- initial), xshift=35mm]
\node[state] (20) {$b_{20}$};
\node[state] (21) [below=of 20] {$b_{21}$};
\begin{scope}[every node/.style={scale=.7}]
\path[->]
(20) edge [bend right] node [left] {$\beta_{21}$} (21)
(21) edge [bend right] node [right] {$\alpha_{22}$} (20);
\end{scope}
\end{scope}
\node[draw,dashed,fit=(B1)] {};
\node[draw,dashed,fit=(B2)] {};
\node[draw,fit=(B)(B1)(B2), inner sep=3mm] {};
\begin{scope}[every edge quotes/.append style={midway, auto}, every edge/.append style={red, ->}]
\draw (20.north) edge [bend right, "$\kappa$"] (initial.north);
\draw (10.north west) edge [bend right, "$\delta$"'] (initial.north east);
\draw (initial.east) edge ["$\gamma$"'] (10.west);
\draw (10) edge ["$\alpha$"] (20);
\draw (11) edge ["$\beta$"] (20);
\end{scope}
\end{tikzpicture}
\end{document}