如何在最左边的“A”和右边的下一个“A”之间添加等号?
以下是我目前所掌握的信息:
\usepackage{graphicx}
\usetikzlibrary{arrows,shapes,decorations,automata,backgrounds,petri,positioning}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{width=7cm,compat=1.3}
\tikzstyle{arrow} = [draw, -latex']
\tikzstyle{node} = [rectangle, draw, text centered]
\begin{document}
\begin{figure}[ht]
\centering
\begin{tikzpicture}[node distance=1.4cm]
\tikzstyle{place}=[circle,thick,draw=gray!75,fill=gray!20,minimum size=6mm]
\node (ae) [node] {A};
\node (a0) [node, right=1.5cm of ae] {A};
\node (a1) [node, right of=a0] {A};
\node (a2) [node, right of=a1] {A};
\node (a3) [node, right of=a2] {A};
\node (x0) [node, below of=ae] {$X_t$};
\node (x1) [node, below of=a0] {$X_0$};
\node (x2) [node, below of=a1] {$X_1$};
\node (x3) [node, below of=a2] {$X_2$};
\node (x4) [node, below of=a3] {$X_t$};
\node (h0) [node, above of=ae] {$h_t$};
\node (h1) [node, above of=a0] {$h_0$};
\node (h2) [node, above of=a1] {$h_1$};
\node (h3) [node, above of=a2] {$h_2$};
\node (h4) [node, above of=a3] {$h_t$};
\draw [red,->] (ae.45) arc (0:240:4mm) node[pos=0.5,above left]{}(ae);
%\draw [=] (ae) -- (a0)
\draw [arrow] (a0) -- (a1);
\draw [arrow] (a1) -- (a2);
\draw [arrow] (a2) -- (a3);
\draw [arrow] (x0) -- (ae);
\draw [arrow] (x1) -- (a0);
\draw [arrow] (x2) -- (a1);
\draw [arrow] (x3) -- (a2);
\draw [arrow] (x4) -- (a3);
\draw [arrow] (ae) -- (h0);
\draw [arrow] (a0) -- (h1);
\draw [arrow] (a1) -- (h2);
\draw [arrow] (a2) -- (h3);
\draw [arrow] (a3) -- (h4);
\end{tikzpicture}
\end{figure}
\end{document}
答案1
下面给出了更简单的代码。不需要更多的库;\foreach
有 2 个变量,\a
方便\b
控制垂直和水平距离。
\documentclass[tikz,border=5mm]{standalone}
\begin{document}
\begin{tikzpicture}[>=latex]
\def\a{2} \def\b{2.2}
\foreach \i/\j in {-1/t,0/0,1/1,2/2,3/t}{
\path[nodes={draw}]
(\i*\b,0) node (a\i) {$A$}
+(0,\a) node (h\i) {$h_{\j}$}
+(0,-\a) node (x\i) {$X_{\j}$}
;
\draw[->] (a\i)--(h\i);
\draw[->] (x\i)--(a\i);
}
\draw[->] (a0)--(a1);
\draw[->] (a1)--(a2);
\draw[->] (a2)--(a3);
\draw[->,magenta] (a-1.north east) arc (0:240:.4);
\path (a-1)--(a0) node[midway,blue]{=};
\end{tikzpicture}
\end{document}
答案2
定位库的使用不是right=of ae
。right of=ae
因此,您应该更改所有节点。然后,您可以添加\node [right=.7cm of ae.center]{=};
标志=
,因为您的node distance
设置为1.4cm
。
\node (ae) [node] {A};
\node (a0) [node, right=of ae] {A};
\node (a1) [node, right=of a0] {A};
\node (a2) [node, right=of a1] {A};
\node (a3) [node, right=of a2] {A};
\node (x0) [node, below=of ae] {$X_t$};
\node (x1) [node, below=of a0] {$X_0$};
\node (x2) [node, below=of a1] {$X_1$};
\node (x3) [node, below=of a2] {$X_2$};
\node (x4) [node, below=of a3] {$X_t$};
\node (h0) [node, above=of ae] {$h_t$};
\node (h1) [node, above=of a0] {$h_0$};
\node (h2) [node, above=of a1] {$h_1$};
\node (h3) [node, above=of a2] {$h_2$};
\node (h4) [node, above=of a3] {$h_t$};
\node [right=.7cm of ae.center]{=};
答案3
尝试以下 MWE:
\documentclass{article}
\usepackage{graphicx}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18,
width=7cm}
\usetikzlibrary{arrows.meta, automata,
backgrounds,
chains,
decorations,
petri, positioning,
shapes}
\begin{document}
\begin{figure}[ht]
\centering
\begin{tikzpicture}[
> = Straight Barb,
node distance = 12mm and 12mm,
start chain = going right,
N/.style = {draw, minimum size=2em}
]
\foreach \i [count=\x] in {t,0,1,2,t,5}
{
\ifnum\x=2
\node (a\x) [N,on chain] {$A$};
\else
\node (a\x) [N,on chain, join=by ->] {$A$};
\fi
\node (x\x) [N, below =of a\x] {$X_{\i}$};
\node (h\x) [N, above =of a\x] {$h_{\i}$};
\draw[->] (x\x) -- (a\x);
\draw[->] (a\x) -- (h\x);
}
\path(a1) -- node {$=$} (a2); % <---
\draw[red,->] (a1.45) arc (0:240:1.414em);
\end{tikzpicture}
\end{figure}
\end{document}
在它使用
- 对于
pgfplots
,还加载tikz
包我建议使用最近的版本1.18
,它引入了许多新功能并修复了从“古老”版本开始的可能错误(是时候升级你的 LaTeX 安装了)。 tikz
定义图像元素样式的最新语法(\tikzstyle
很久以前就被弃用了)- 带有节点的行
A
通过使用chains
库进行定位,并通过宏将前两个异常连接起来join = by ->
- 前两个,你的问题是什么,是由中间的
path
节点连接的。=
MWE 编译的结果是: