我正在尝试制作一个有限状态自动机,其中一个节点内部包含另一个 FSA,但内部和节点本身显示为虚线,这是我不想要的。我只希望外部节点为虚线。
这就是我所拥有的:
\documentclass[14pt]{report}
\usepackage[utf8]{inputenc}
\usepackage{pgf}
\usepackage{tikz}
\usetikzlibrary{arrows,automata}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{blkarray}
\begin{document}
\begin{tikzpicture}[->,>=stealth',auto,node distance=2.8cm]
\node[state, dashed] (A) {$
\begin{tikzpicture}[->,>=stealth',auto,node distance=2.8cm]
\tikzstyle{every state}=[draw=black]
\node[state] (A) {$A$};
\node[state] (B) [right of=A] {$B$};
\draw (A) to[loop left] node[auto] {$f$} (A);
\draw (B) to[bend left] node[auto] {$f$} (A);
\draw (A) to[bend left] node[auto] {$g$} (B);
\draw (B) to[loop right] node[auto] {$g$} (B);
\end{tikzpicture}
$};
\draw (A) node[auto] {} (A);
\end{tikzpicture}
\end{document}
但是tikzstyle的效果并没有体现出来。
答案1
避免嵌套tikzpicture
(已知问题)的解决方案。
首先绘制内部节点。然后使用拟合库放置外部节点fit
。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows}
\usetikzlibrary{automata}
\usetikzlibrary{fit}
\begin{document}
\begin{tikzpicture}[->,>=stealth',auto,node distance=2.8cm]
\begin{scope}
\tikzstyle{every state}=[draw=black]
\node[state] (A) {$A$};
\node[state] (B) [right of=A] {$B$};
\draw (A) to[loop left] node[auto] (tmp1) {$f$} (A);
\draw (B) to[bend left] node[auto] (tmp2) {$f$} (A);
\draw (A) to[bend left] node[auto] (tmp3) {$g$} (B);
\draw (B) to[loop right] node[auto] (tmp4) {$g$} (B);
\end{scope}
\node[
state,
dashed,
fit=(tmp1) (tmp2) (tmp3) (tmp4),
inner sep=0pt, % The padding is already provided by the inner
% annotation nodes.
] (A) {}; % Overwrites the previous (A), or a different name can be used.
\end{tikzpicture}
\end{document}
另一个优点是现在可以轻松访问内部节点,例如从内部节点或向内部节点绘制箭头。
答案2
因此,这里的问题是,当您写入时\node[dashed]
,它会自动将该格式“虚线”绘制到该环境内的任何内容上。
一个简单的逆转方法是在节点内部的 tikzpicture 上添加单词“solid”。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{automata}
\usetikzlibrary{arrows}
\begin{document}
\begin{tikzpicture}[->,>=stealth',auto,node distance=2.8cm]
\node[state, dashed] (A) {$
\begin{tikzpicture}[->,>=stealth',auto,node distance=2.8cm, solid]
\tikzstyle{every state}=[draw=black]
\node[state] (A) {$A$};
\node[state] (B) [right of=A] {$B$};
\draw (A) to[loop left] node[auto] {$f$} (A);
\draw (B) to[bend left] node[auto] {$f$} (A);
\draw (A) to[bend left] node[auto] {$g$} (B);
\draw (B) to[loop right] node[auto] {$g$} (B);
\end{tikzpicture}
$};
\draw (A) node[auto] {} (A);
\end{tikzpicture}
\end{document}