TikZ:强制两张图片使用相同的基线/参考框架

TikZ:强制两张图片使用相同的基线/参考框架

我有两个 TikZ 自动机,我想将它们并排放置: 在此处输入图片描述

但是,我更希望“开始”节点在页面上垂直对齐。如果我添加足够大的辅助线来覆盖两个图,就会自动发生这种情况: 在此处输入图片描述

这是下图的代码;注释掉帮助行会得到上面的图像。

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{automata}
\usetikzlibrary{positioning}

\begin{document}
\tikzstyle{negative} = [circle, minimum width=8pt, fill, inner sep=0pt]
\begin{tikzpicture}[->,shorten >=1pt,auto,node distance=1.4cm,on grid,semithick,inner sep=2pt,bend angle=25]
\draw[help lines] (-1,-1.2) grid (3,2);
\node[initial,negative] (A) {};
\node[negative] (B) [above right=of A] {};
\node[negative,accepting] (C) [below right=of B] {};
\path [every node/.style={font=\footnotesize}]
(A)
edge node {$f$} (B)
edge [swap] node {$h$} (C)
(B)
edge [bend left] node {$m$} (C)
edge [bend right,swap] node {$n$} (C)
;
\end{tikzpicture}%
\qquad%
\begin{tikzpicture}[->,shorten >=1pt,auto,node distance=1.4cm,on grid,semithick,inner sep=2pt,bend angle=45]
\draw[help lines] (-1,-1.2) grid (3,2);
\node[initial,negative] (A) {};
\node[negative] (B) [above right=of A] {};
\node[negative,accepting] (C) [below right=of B] {};
\node[negative] (D) [below right=of A] {};
\path [every node/.style={font=\footnotesize}]
(A)
edge node {$f$} (B)
edge [swap] node {$h$} (C)
edge [swap] node {$g$} (D)
(B)
edge node {$n$} (C)
(D)
edge [swap] node {$m$} (C)
;
\end{tikzpicture}
\end{document}

不借助帮助热线的情况下,我怎样才能得到较低的数字?

答案1

一种方法是使用选项baseline中的键tikzpicture来指定每张图片应该通过特定的节点名称与基线对齐(这里我使用了(A)):

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{automata}
\usetikzlibrary{positioning}

\begin{document}
\tikzstyle{negative} = [circle, minimum width=8pt, fill, inner sep=0pt]
\begin{tikzpicture}[baseline=(A),->,shorten >=1pt,auto,node distance=1.4cm,on grid,semithick,inner sep=2pt,bend angle=25]
\node[initial,negative] (A) {};
\node[negative] (B) [above right=of A] {};
\node[negative,accepting] (C) [below right=of B] {};
\path [every node/.style={font=\footnotesize}]
(A)
edge node {$f$} (B)
edge [swap] node {$h$} (C)
(B)
edge [bend left] node {$m$} (C)
edge [bend right,swap] node {$n$} (C)
;
\end{tikzpicture}%
\qquad%
\begin{tikzpicture}[baseline=(A),->,shorten >=1pt,auto,node distance=1.4cm,on grid,semithick,inner sep=2pt,bend angle=45]
\node[initial,negative] (A) {};
\node[negative] (B) [above right=of A] {};
\node[negative,accepting] (C) [below right=of B] {};
\node[negative] (D) [below right=of A] {};
\path [every node/.style={font=\footnotesize}]
(A)
edge node {$f$} (B)
edge [swap] node {$h$} (C)
edge [swap] node {$g$} (D)
(B)
edge node {$n$} (C)
(D)
edge [swap] node {$m$} (C)
;
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容