Tikz 箭头形状不符合预期

Tikz 箭头形状不符合预期

我尝试使用此代码来生成下图。

\documentclass[statementpaper,11pt,twoside]{memoir}

\usepackage{tikz}
\usetikzlibrary{fit,positioning}

\begin{document}

\begin{center}
\begin{tikzpicture}[]
    \tikzstyle{vertex} = [rectangle, rounded corners, minimum width=2cm, minimum height=0.8cm, text centered, draw=green!60, fill=green!5, very thick]
    \tikzstyle{hidden} = [draw=none, minimum width=1cm, minimum height=0.8cm, text centered]
    \tikzstyle{arrow} = [->,thick]

    \node[vertex, minimum width=2cm] (y) at (1,0) {p1};

    \node[vertex] (y1) [below=0.7cm of y] {p1};
    \node[vertex, minimum width=1.5cm] (y11) [right=0.7cm of y1] {p2}; 
    \node[vertex, minimum width=1cm] (y12) [right=0.7cm of y11] {p3};
    \draw[arrow] (y) to [out=270,in=100] (y1);
    \draw[arrow] (y) to [out=270,in=150] (y11);
    \draw[arrow] (y) to [out=270,in=140] node[above] {\footnotesize Text along arrow} (y12);
    
\end{tikzpicture}
\end{center}

\end{document}

产生的输出:

在此处输入图片描述

我的期望:

在此处输入图片描述

我怎样才能得到我想要的输出正确弯曲箭头并设置文本。

答案1

您可以指定distance=0.75cm]收益:

在此处输入图片描述

我的建议是实际增加更多的垂直间距,这样就不会太拥挤。

您还可以添加sloped选项以使文本跟随箭头的倾斜,但由于它非常平坦,因此我认为这不是一个好主意。

笔记:

代码:

\documentclass[statementpaper,11pt,twoside]{memoir}

\usepackage{tikz}
\usetikzlibrary{fit,positioning}

\begin{document}

\begin{center}
\begin{tikzpicture}[]
    \tikzstyle{vertex} = [rectangle, rounded corners, minimum width=2cm, minimum height=0.8cm, text centered, draw=green!60, fill=green!5, very thick]
    \tikzstyle{hidden} = [draw=none, minimum width=1cm, minimum height=0.8cm, text centered]
    \tikzstyle{arrow} = [->,thick]

    \node[vertex, minimum width=2cm] (y) at (1,0) {p1};

    \node[vertex] (y1) [below=0.7cm of y] {p1};
    \node[vertex, minimum width=1.5cm] (y11) [right=0.7cm of y1] {p2}; 
    \node[vertex, minimum width=1cm] (y12) [right=0.7cm of y11] {p3};
    \draw[arrow] (y) to [out=270,in=100] (y1);
    \draw[arrow] (y) to [out=270,in=150] (y11);
    \draw[arrow, draw=red] (y) to [out=270,in=140,distance=0.75cm] node[above] {\footnotesize Text along arrow} (y12);
    
\end{tikzpicture}
\end{center}

\end{document}

答案2

您可能喜欢以下解决方案。

\documentclass[statementpaper,11pt,twoside]{memoir}

\usepackage{tikz}
\usetikzlibrary{decorations.text,
                positioning,       
                quotes}            

\begin{document}
    \begin{center}
    \begin{tikzpicture}[
  node distance = 7mm,
  vertex/.style = {rectangle, rounded corners, thick, draw=green!60, fill=green!5,
                   minimum width=#1, minimum height=0.8cm, align=center},
vertex/.default = 2cm,
tap/.style args = {#1/#2}{decoration={raise=#1,
                                      text along path,
                                      text align={left indent=4em},
                                      text={|\scriptsize| #2},
                                      },
                          postaction={decorate}
                         },
 arrow/.style = {->,thick}
                        ]
\node[vertex] (y)   {p1};
\node[vertex] (y1)  [below=of y] {p1};
\node[vertex=1.5cm] (y11) [right=of y1]     {p2};
\node[vertex=1.0cm] (y12) [right=of y11]    {p3};
%
\draw[arrow] (y) to [out=270,in=115] (y1);
\draw[arrow] (y) to [out=270,in=155] (y11);

\draw[arrow, tap={4pt/text along path}]
             (y) to [out=270,in=135, looseness=0.5] (y12); % <---
    \end{tikzpicture}
    \end{center}
\end{document}

如您所见,最后一条路径的“损失”由其out looseness=0.5起点处的曲线的距离减少来控制。

在此处输入图片描述

相关内容