解释

解释

解释

看来,pos=.25使用语法时可以将节点小心地放置在路径上(即从节点 BEGIN 到节点 END 的 25%)--(参见示例 A)。

问题

使用语法构造的路径无法获得与上述相同的精度to(参见示例 B.)。相反,我使用

postaction={decorate,decoration={text along path,text={|\ttfamily|TCP}}} 

示例 A。请注意我可以这样做:

\draw [<->] (data.south east) -- (app.north west) 
node [pos=.5, above, sloped] (TextNode) {TCP};

示例 B。请注意我不能这样做:

\draw [icoarrow,<->] (data.south east) to[out=90,in=270] (app.north west) 
node [pos=.5, above, sloped] (TextNode) {TCP};

例子

\documentclass{article}
\usepackage{fontspec}
\usepackage{tikz}
\usetikzlibrary{positioning,decorations.text}


\begin{document}
\begin{tikzpicture}[node distance=2cm]
    \node (data) {Data};
    \node [right=of data] (app) {App};
    % Lines
    \draw [<->] (data) -- (app) node [pos=.5, above, sloped] (TextNode) {TCP}; % works fine
    \draw [<->] (data) to[out=90,in=90] (app) node [pos=.5, above, sloped] (TextNode) {TCP}; % does not work
    \draw [<->,postaction={decorate,decoration={text along path,text align=center,text={TCP}}}]  (data) to[out=90,in=90] (app); % works fine
    %\draw [<->,postaction={decorate,decoration={text along path,pos=.25,text={TCP}}}]  (data) to[out=90,in=90] (app); % does not work (causes error)
\end{tikzpicture}
\end{document}

答案1

为一个:

node把右边的to[out=90,in=90]点赞放在后面

\draw [<->] (data) to[out=90,in=90]node [pos=.5, above, sloped] (TextNode) {TCP} (app) ;

对于 B,执行以下操作:

\draw[<->,postaction={decorate,decoration={text along path,raise=1ex,text align=center,text={TCP}}}]   (data) to[out=90,in=90] (app);

完整代码:

\documentclass{article}
%\usepackage{fontspec}
\usepackage{tikz}
\usetikzlibrary{positioning,decorations.text}


\begin{document}
\begin{tikzpicture}[node distance=2cm]
    \node (data) {Data};
    \node [right=of data] (app) {App};
    % Lines
    \draw [<->] (data) -- (app) node [pos=.5, above, sloped] (TextNode) {TCP}; % works fine
    \draw [<->] (data) to[out=90,in=90]node [pos=.5, above, sloped] (TextNode) {TCP} (app) ; % does not work
\end{tikzpicture}
\begin{tikzpicture}[node distance=2cm]
    \node (data) {Data};
    \node [right=of data] (app) {App};
    % Lines    
    \draw[<->,postaction={decorate,decoration={text along path,raise=1ex,text align=center,text={TCP}}}]   (data) to[out=90,in=90] (app); % does not work (causes error)
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容