在 Tikz 图片的箭头标记上添加标签

在 Tikz 图片的箭头标记上添加标签

我尝试手动在连接线中心的箭头尖端放置标签(1-2-3-4),但似乎效果不佳。我该如何解决这个问题?

在此处输入图片描述

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,intersections,shapes.geometric,decorations.pathmorphing,decorations.pathreplacing,decorations.shapes,decorations.markings,patterns,calc,fit,arrows,backgrounds,matrix}

\begin{document}
\begin{tikzpicture}[auto]

\tikzset{deco/.style={decoration={markings, mark=at position #1 with {\arrow{>} }},postaction={decorate}}}
\tikzset{trape/.style={trapezium,draw,shape border rotate=90,minimum width=2cm}}
\tikzset{box/.style={rectangle,draw,minimum height=1cm,minimum width=2.5cm}}
\tikzset{cerchi/.style={circle,draw,minimum size=1cm}}

\matrix [row sep={1.5cm}]
{
                            &[2cm]  \node [box] (genera) {}; &[2cm]                         &[1cm] \\
 \node [cerchi] (pompa) {}; &                                & \node [trape] (turbina) {};  & \node [cerchi] (ultiliz) {}; \\
                            & \node [cerchi] (condensa) {};  &                              &      \\
};

\begin{scope}[>=triangle 60]
 \draw [deco=0.6]  (genera)                      -|  node[pos=0.6]{2} (turbina.top right corner);
 \draw [deco=0.6]  (turbina.bottom left corner) |-   node[above=1mm,pos=0.71]{3} (condensa);
 \draw [deco=0.4]  (condensa)                    -|  node[above=1mm,pos=0.31]{4} (pompa);
 \draw [deco=0.6]  (pompa)                      |-   node[below=1mm,pos=0.63]{1} (genera);
\end{scope}

\draw [->,>=latex,very thick, shorten >=4 pt,shorten <=4pt] (pompa.south)--(pompa.north);

\node [coordinate] (B) at ($ (condensa.center)!.6!(condensa.west) $) {};
\node [coordinate] (C) at ($ (condensa.center)!.6!(condensa.east) $) {};
\node [coordinate] (A) at ($ (B)+(0,-1.5cm)$) {};
\node [coordinate] (D) at ($ (C)+(0,-1.5cm)$) {};
\draw (A)--(B);
\draw[decorate,decoration={zigzag,amplitude=3pt,segment length=8pt}] (B)--(C);
\draw (C)--(D);
\end{tikzpicture}



\end{document}

答案1

正如我评论的那样你的一个问题您可以在deco样式中添加一个节点来对箭头进行编号。这是它的自定义版本,它将数字始终放在线的左侧(相对于方向)。将更改为-90相对+90右侧,或进一步微调以进行另一次移位。

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.markings}
\begin{document}
\begin{tikzpicture}
\tikzset{deco/.style 2 args={
            decoration={             
                        markings,   
                        mark=at position {#1} with { 
                                    \arrow{latex},
                                    \node[anchor=\pgfdecoratedangle-90] {#2};
                        }
            },
            postaction={decorate}
    }
}
\draw[deco={0.5}{A}] (0,0) -- (0,2);
\draw[deco={0.75}{B},deco={0.2}{C}] (0,2) -- (2,1);
\draw[deco={0.9}{D}] (2,1) -- (0,0);
\end{tikzpicture} 
\end{document}

这将使

在此处输入图片描述

答案2

哇哦,Percusse...我使用了和你类似的代码,真是太不可思议了(对我来说 ;))。这是我使用的:

在此处输入图片描述

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.markings,arrows}

\begin{document}
\begin{tikzpicture}[auto]

\tikzset{deco/.style n args={3}{decoration={markings, mark=at position #1 with { \draw [->,>=triangle 60] (0,0) --  (3pt,0)node [near end,#2=5 pt]{#3};}},  postaction={decorate}}}

 \draw [deco={0.5}{left}{3}]   (0,0)--(0,2);
 \draw [deco={0.5}{above}{4}]  (0,2)--(3,2);
 \draw [deco={0.5}{right}{1}]  (3,2)--(3,0);
 \draw [deco={0.5}{below}{2}]  (3,0)--(0,0); 

\end{tikzpicture}
\end{document}

也许我现在会根据你的提示来修改我的代码!非常感谢!

相关内容