Tikz で 2 つのノード間の描画

Tikz で 2 つのノード間の描画

ノード間の中央に水平の青い実線を描画できない理由を解明しようとしています。

\documentclass{article}
\usepackage{tikz,amsmath}
\usetikzlibrary{positioning}
\begin{document}
\begin{center}
\begin{tikzpicture}
\node(X)[draw,rectangle, rounded corners,draw=black, 
          fill=white,align=center,xshift=-6cm]
          {\large Input \textcolor{red}{$2$}};%
\node(Y)[draw,rectangle, rounded corners,draw=black, 
          fill=white,align=center,xshift=-.5cm]
          {\large $\begin{aligned}[t] g(\textcolor{red} 
    {2})&=\textcolor{red}{2}^{2}+1\\ &=5\end{aligned}$\\ 
    \large The output of $g$, \textcolor{blue}{$5$},is\\ 
    \large the input to $f$};%
\node (Z)[draw,rectangle, rounded corners,draw=black, 
          fill=white,align=center,xshift=6cm]
         {\large $\begin{aligned}[t] f(\textcolor{blue} 
     {5})&=4(\textcolor{blue}{5})-3\\ &=17\end{aligned}$};%
\end{tikzpicture}
\end{center}

\begin{tikzpicture}
\draw[blue,thick,-latex] (X.east) to ( Y.west);
\end{tikzpicture}
\end{document}

ここに画像の説明を入力してください

答え1

2 つの別々の を使用する場合は、それぞれと をtikzpicture追加する必要があります。remember pictureoverlay,remember picture

\documentclass{article}
\usepackage{tikz,amsmath}
\usetikzlibrary{positioning}
\begin{document}
\begin{center}
\begin{tikzpicture}[remember picture]
\node(X)[draw,rectangle, rounded corners,draw=black, 
          fill=white,align=center,xshift=-6cm]
          {\large Input \textcolor{red}{$2$}};%
\node(Y)[draw,rectangle, rounded corners,draw=black, 
          fill=white,align=center,xshift=-.5cm]
          {\large $\begin{aligned}[t] g(\textcolor{red} 
    {2})&=\textcolor{red}{2}^{2}+1\\ &=5\end{aligned}$\\ 
    \large The output of $g$, \textcolor{blue}{$5$},is\\ 
    \large the input to $f$};%
\node (Z)[draw,rectangle, rounded corners,draw=black, 
          fill=white,align=center,xshift=6cm]
         {\large $\begin{aligned}[t] f(\textcolor{blue} 
     {5})&=4(\textcolor{blue}{5})-3\\ &=17\end{aligned}$};%
\end{tikzpicture}
\end{center}

\begin{tikzpicture}[overlay,remember picture]
\draw[blue,thick,-latex] (X.east) to ( Y.west);
\end{tikzpicture}
\end{document}

もちろん、 1 つだけ使用することもできますtikzpicture

\documentclass{article}
\usepackage{tikz,amsmath}
\usetikzlibrary{positioning}
\begin{document}
\begin{center}
\begin{tikzpicture}
\node(X)[draw,rectangle, rounded corners,draw=black, 
          fill=white,align=center,xshift=-6cm]
          {\large Input \textcolor{red}{$2$}};%
\node(Y)[draw,rectangle, rounded corners,draw=black, 
          fill=white,align=center,xshift=-.5cm]
          {\large $\begin{aligned}[t] g(\textcolor{red} 
    {2})&=\textcolor{red}{2}^{2}+1\\ &=5\end{aligned}$\\ 
    \large The output of $g$, \textcolor{blue}{$5$},is\\ 
    \large the input to $f$};%
\node (Z)[draw,rectangle, rounded corners,draw=black, 
          fill=white,align=center,xshift=6cm]
         {\large $\begin{aligned}[t] f(\textcolor{blue} 
     {5})&=4(\textcolor{blue}{5})-3\\ &=17\end{aligned}$};%
\draw[blue,thick,-latex] (X.east) to ( Y.west);  
\end{tikzpicture}
\end{center}

\end{document}

両方のコードの出力は

ここに画像の説明を入力してください

答え2

シュレディンガーの猫の答えの 2 番目の例に触発されました。ライブラリchainsとマクロを使用してjoin、すべてのノードに共通のスタイルを配置および定義します。

\documentclass{article}
\usepackage{tikz,amsmath}
\usetikzlibrary{chains,
                positioning}

\begin{document}
    \begin{center}
\begin{tikzpicture}[
    node distance = 22mm,
      start chain = going right,
       box/.style = {draw, rounded corners, font=\large,
                     align=center, on chain},
every join/.style = {blue,thick,-latex}
              ]
\node (X) [box] {Input \textcolor{red}{$2$}};%
\node (Y) [box, join] 
                {$\begin{aligned}[t] 
                g(\textcolor{red}{2})   & = \textcolor{red}{2}^{2}+1\\ 
                                        & = 5               
                \end{aligned}$\\
                The output of $g$, \textcolor{blue}{$5$}, \\
                is the input to $f$};   
\node (Z) [box] {$\begin{aligned}[t] 
                f(\textcolor{blue}{5})  & = 4(\textcolor{blue}{5})-3\\ 
                                        & = 17
                \end{aligned}$};%
\end{tikzpicture}
    \end{center}
\end{document}

ここに画像の説明を入力してください

関連情報