向节点添加水平偏移(TikZ)

向节点添加水平偏移(TikZ)

我目前正在尝试创建一个小图表,其中两个节点之间有箭头,箭头旁边有文本。

目前,我的图表如下所示:

在此处输入图片描述

但是,我希望箭头左侧的文字从 Raspberry Pi 指向 SIM7600E-H 4G HAT。

梅威瑟:

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows}
\usetikzlibrary{calc}

\tikzstyle{process} = [rectangle, minimum width=6cm, minimum height=1cm, text centered, text width=6cm, draw=black, fill=orange!30]
\tikzstyle{arrow} = [thick,->,>=stealth]

\begin{document}
    \begin{figure}
        \centering
        \begin{tikzpicture}[node distance=4cm]
            \node (rpi) [process] {Raspberry Pi};
            \node (sim) [process, below of=rpi] {SIM7600E-H 4G HAT};
            
            \node (command) at ($(rpi) !0.5! (sim)$) {Send AT command};

            \draw [arrow] (rpi.west) -- node[anchor=south] {} +(-1.5, 0) |- (sim);
            \draw [arrow] (sim.east) -- node[anchor=south] {} +(1.5, 0)  |- (rpi);
        \end{tikzpicture}
    \end{figure}
\end{document}

答案1

您已经非常接近期望的结果了。只需在箭头处的节点中添加文本即可:

\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                calc,
                positioning}

\begin{document}
\begin{figure}
    \centering
    \begin{tikzpicture}[
 node distance = 11mm and 5mm,
    arr/.style = {-Stealth, thick},
process/.style = {draw, fill=orange!30, 
                  minimum height=1cm, text width=6cm, align=center}
                        ]
\node (rpi) [process] {Raspberry Pi};
\node (sim) [process, below=of rpi] {SIM7600E-H 4G HAT};
%
\node (command) at ($(rpi) !0.5! (sim)$) {Send AT command};
%
\draw [arr] (rpi.west) -- ++(-1,0) |- (sim) node[pos=0.25, left] {text};
\draw [arr] (sim.east) -- +(1, 0)  |- (rpi);
    \end{tikzpicture}
\end{figure}
\end{document}

在此处输入图片描述

或者你遵循以下做法:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                positioning}

\begin{document}
\begin{figure}
    \centering
    \begin{tikzpicture}[
 node distance = 11mm and 5mm,
    arr/.style = {-Stealth, thick},
    lbl/.style = {font=\small, align=center},
process/.style = {draw, fill=orange!30, 
                  minimum height=1cm, text width=6cm, align=center}
                        ]
\node (rpi) [process] {Raspberry Pi};
\node (sim) [process, below=of rpi] {SIM7600E-H 4G HAT};
%
\draw [arr] (rpi.west) -- ++(-1,0) |- (sim) node[lbl, pos=0.25, left] {Send AT\\ command};
\draw [arr] (sim.east) -- +(1, 0)  |- (rpi);
    \end{tikzpicture}
\end{figure}
\end{document}

在此处输入图片描述

答案2

也许你喜欢这个。

在此处输入图片描述

\documentclass[tikz,border=5mm]{standalone}
\begin{document}
\begin{tikzpicture}[thick,>=stealth]
\path[nodes={draw,fill=yellow!50,minimum width=5cm,minimum height=9mm}]
(0,0)    node (Ras) {Raspberry Pi}
(0,-2.5) node (SIM) {SIM7600E-H 4G HAT}
;
\draw[<-] (Ras)--+(3.5,0)|-(SIM);       
\draw[->] (Ras)--+(-3.5,0)|-(SIM) node[pos=.25,align=center,left]{Send AT \\command};
\end{tikzpicture}
\end{document}

相关内容