我正在尝试制作此图像,其中包含三个标签和三个图表,全部由 (Java) 程序自动生成。该程序生成图表(具体而言是有限状态自动机的图表),并使用 LaTeX 和 TikZ 将这些图表呈现给客户。这些图表往往很大,通常非常大,并且很难通过编程调整流程以进行渲染。
上面的图片是由本题末尾的 LaTeX 输入生成的。您会注意到它由三个节点和三个图组成。它们的位置是我手动计算出来的魔法数字。在图表之前或之后添加任何内容相当容易,但无法调整节点和边的实际列表。也不可能提前知道图表上会出现哪些节点。
问题是是否有可能用某种可以计算其大小的东西来封闭图形和节点,然后将它们放置在链中。
另一个限制是整个演讲应该在单一tikzpicture
环境中进行。
\documentclass{sciposter}
\usepackage[paperwidth=84cm,paperheight=120cm,centering,textwidth=74cm,textheight=100cm,left=2cm,top=2cm]{geometry}
\usepackage{tikz}
\begin{document}
\usetikzlibrary{graphs,chains,shapes,quotes}
\usetikzlibrary{automata, positioning, arrows}
\usetikzlibrary{graphdrawing}
\usegdlibrary{trees,force,layered,circular}
\tikzstyle{accept}=[fill=green!50]
\tikzstyle{initial}=[circle,draw]
\tikzstyle{every node}=[rectangle]
\tikzstyle{epsilon}=[]
\tikzstyle{graphs/every graph}=[simple necklace layout,
nodes={ellipse,fill=olive!20,inner sep=2pt,outer sep=2pt}, level sep =12ex, sibling sep=4ex, node distance = 35ex]
\def\magicOne{(0,-3)}
\def\magicTwo{(0,-63)}
\def\magicThree{(0,-95)}
\begin{tikzpicture}
\node at (0,0) {\Huge NFSA};
\node at (0,-61) {\Huge DFSA};
\node at (0,-92) {\Huge Minimized DFSA};
\begin{scope} \path \magicOne
graph{
"$q_{0}$" [initial,accept] -> ["\varepsilon"] "$q_{1}$" ;
"$q_{0}$" -> ["a, b"] "$q_{2}$" ;
"$q_{0}$" -> [""] "$q_{3}$" ;
"$q_{0}$" -> [""] "$q_{8}$" ;
"$q_{0}$" -> ["\varepsilon",loop] "$q_{0}$" ;
"$q_{1}$" -> ["a, b"] "$q_{2}$" ;
"$q_{1}$" -> [""] "$q_{3}$" ;
"$q_{1}$" -> ["\varepsilon"] "$q_{8}$" ;
"$q_{2}$" -> ["a, b",loop] "$q_{2}$" ;
"$q_{3}$" -> ["b"] "$q_{2}$" ;
"$q_{3}$" -> ["a"] "$q_{4}$" ;
"$q_{3}$" -> [""] "$q_{5}$" ;
"$q_{4}$" -> ["a, b"] "$q_{2}$" ;
"$q_{4}$" -> ["\varepsilon"] "$q_{5}$" ;
"$q_{5}$" -> ["a"] "$q_{2}$" ;
"$q_{5}$" -> [""] "$q_{6}$" ;
"$q_{5}$" -> [""] "$q_{7}$" ;
"$q_{5}$" -> [""] "$q_{10}$" ;
"$q_{5}$" -> ["b"] "$q_{12}$" ;
"$q_{6}$" -> ["a, b"] "$q_{2}$" ;
"$q_{6}$" -> ["\varepsilon"] "$q_{7}$" ;
"$q_{6}$" -> ["\varepsilon"] "$q_{10}$" ;
"$q_{7}$" -> ["a"] "$q_{2}$" ;
"$q_{7}$" -> [""] "$q_{1}$" ;
"$q_{7}$" -> [""] "$q_{3}$" ;
"$q_{7}$" -> [""] "$q_{8}$" ;
"$q_{7}$" -> [""] "$q_{0}$" ;
"$q_{7}$" -> ["b"] "$q_{9}$" [accept];
"$q_{8}$" -> ["a, b"] "$q_{2}$" ;
"$q_{8}$" -> ["\varepsilon"] "$q_{3}$" ;
"$q_{9}$" -> [""] "$q_{1}$" ;
"$q_{9}$" -> ["a, b"] "$q_{2}$" ;
"$q_{9}$" -> [""] "$q_{3}$" ;
"$q_{9}$" -> [""] "$q_{8}$" ;
"$q_{9}$" -> ["\varepsilon"] "$q_{0}$" ;
"$q_{10}$" -> ["b"] "$q_{2}$" ;
"$q_{10}$" -> [""] "$q_{1}$" ;
"$q_{10}$" -> [""] "$q_{3}$" ;
"$q_{10}$" -> [""] "$q_{8}$" ;
"$q_{10}$" -> [""] "$q_{0}$" ;
"$q_{10}$" -> ["a"] "$q_{11}$" [accept];
"$q_{11}$" -> [""] "$q_{1}$" ;
"$q_{11}$" -> ["a, b"] "$q_{2}$" ;
"$q_{11}$" -> [""] "$q_{3}$" ;
"$q_{11}$" -> [""] "$q_{8}$" ;
"$q_{11}$" -> ["\varepsilon"] "$q_{0}$" ;
"$q_{12}$" -> ["\varepsilon"] "$q_{6}$" ;
"$q_{12}$" -> ["a, b"] "$q_{2}$" ;
"$q_{12}$" -> [""] "$q_{7}$" ;
"$q_{12}$" -> [""] "$q_{10}$" ;
}
; \end{scope}
\begin{scope} \path \magicTwo
graph{
"$q_{0}$" [initial,accept] -> ["b"] "$q_{1}$" ;
"$q_{0}$" -> ["a"] "$q_{2}$" ;
"$q_{1}$" -> ["a, b",loop] "$q_{1}$" ;
"$q_{2}$" -> ["a"] "$q_{1}$" ;
"$q_{2}$" -> ["b"] "$q_{3}$" ;
"$q_{3}$" -> ["a"] "$q_{4}$" [accept];
"$q_{3}$" -> ["b"] "$q_{5}$" [accept];
"$q_{4}$" -> ["b"] "$q_{1}$" ;
"$q_{4}$" -> ["a"] "$q_{2}$" ;
"$q_{5}$" -> ["b"] "$q_{1}$" ;
"$q_{5}$" -> ["a"] "$q_{2}$" ;
}
; \end{scope}
\begin{scope} \path \magicThree
graph{
"$q_{0}$" [initial,accept] -> ["b"] "$q_{1}$" ;
"$q_{0}$" -> ["a"] "$q_{2}$" ;
"$q_{1}$" -> ["a, b",loop] "$q_{1}$" ;
"$q_{2}$" -> ["a"] "$q_{1}$" ;
"$q_{2}$" -> ["b"] "$q_{3}$" ;
"$q_{3}$" -> ["a, b"] "$q_{0}$" ;
}
; \end{scope}
\end{tikzpicture}
\end{document}
答案1
这里的图表(来自@Symbol 1)呈链状:
\documentclass[tikz, border=1cm]{standalone}
\begin{document}
\begin{tikzpicture}[even odd rule]
\begin{scope}
\clip[shift={(13,-3)}] (-7.3,0) arc(180:270:5.2) -- (-1.5,-4.3) arc(270:180:4.3) -- cycle (-21,-6) rectangle (25,9);
\fill (6,5) arc( 90:-90:5) -- (-2,-5) arc( 270:90:5) -- cycle (-1.5,4.5) -- (5.5,4.5) arc( 90:-90:4.5) -- (-1.5,-4.5) arc( 270:90:4.5) -- cycle;
\draw foreach\i in{1,...,20}{
foreach\j in{1,...,\j}{
(\i*18:4)--(\j*18:4)
}
};
\end{scope}
\clip (6.2,5.2) arc(90:0:5.2) -- (9.6,0) arc(0:90:4.3) -- cycle (-8,-9) rectangle (38,6);
\begin{scope}
\clip[shift={(26,0)}] (-7.3,0) arc(180:270:5.2) -- (-1.5,-4.3) arc(270:180:4.3) -- cycle (-22,-9) rectangle (12,6);
\fill[shift={(13,-3)}] (6,5) arc( 90:-90:5) -- (-2,-5) arc( 270:90:5) -- cycle (-1.5,4.5) -- (5.5,4.5) arc( 90:-90:4.5) -- (-1.5,-4.5) arc( 270:90:4.5) -- cycle;
\draw[shift={(15,-3)}] foreach\i in{1,...,10}{
foreach\j in{1,...,\j}{
(\i*36:2)--(\j*36:2)
}
};
\end{scope}
\clip[shift={(13,-3)}] (6.2,5.2) arc(90:0:5.2) -- (9.6,0) arc(0:90:4.3) -- cycle (0,-3) rectangle (25,9);
\fill[shift={(26,0)}] (6,5) arc( 90:-90:5) -- (-2,-5) arc( 270:90:5) -- cycle (-1.5,4.5) -- (5.5,4.5) arc( 90:-90:4.5) -- (-1.5,-4.5) arc( 270:90:4.5) -- cycle;
\draw[shift={(29,0)}] foreach\i in{1,...,15}{
foreach\j in{1,...,\j}{
(\i*24:3)--(\j*24:3)
}
};
\end{tikzpicture}
\end{document}
答案2
\matrix
将为你计算间距/移位
\documentclass{article}
\usepackage{fullpage,tikz}
\begin{document}
\tikz{
\matrix{
\draw foreach\i in{1,...,10}{
foreach\j in{1,...,\j}{
(\i*36:2)--(\j*36:2)
}
};
\\
\draw foreach\i in{1,...,15}{
foreach\j in{1,...,\j}{
(\i*24:3)--(\j*24:3)
}
};
\\
\draw foreach\i in{1,...,20}{
foreach\j in{1,...,\j}{
(\i*18:4)--(\j*18:4)
}
};
\\}
}
\end{document}