2

How can I add an equals sign between the leftmost "A" and the next "A" to the right?

enter image description here

Here's what I have so far:

\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}

3 Answers3

7

The following gives a simpler code. No more library is needed; handy \foreach with 2 variables; \a and \b for controlling the vertical and horizontal distances.

enter image description here

\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}

Black Mild
  • 17,569
6

The usage of the positioning library is right=of ae not right of=ae. So you should change all your nodes. Then you can add \node [right=.7cm of ae.center]{=}; for your = sign, since your node distance is set to 1.4cm.

enter image description here

    \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]{=};
Sandy G
  • 42,558
6

Try the following 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}

In it is used

  • for pgfplots, which also load tikz package I suggest to use recent version 1.18 which introduce many new functionalities and fix may bugs from the "ancient" version onwards (it is time to upgrade your LaTeX installation).
  • recent tikz syntax for defining styles of image elements (\tikzstyle is deprecated for long time ago)
  • rows with nodes A are positioned by use of chains library and connected with exception the first two by macro join = by ->
  • first two, what was your problem, are connected by path with node with = in the middle.

Result of MWE compilations is:

enter image description here

Zarko
  • 296,517