4

Explanation

It seems that nodes can be carefully placed on paths using pos=.25 (i.e. 25% from node BEGIN to node END) when using -- syntax (see Example A).

Problem

I cannot have the same precision as above with paths constructed using the to syntax (see Example B.). Instead, I have resulted to using

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

Example A. Note that I can do:

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

Example B. Note that I cannot do:

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

Example

\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}
8

For A:

Put the node right after to[out=90,in=90] like

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

For B, do this:

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

Full code:

\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}

enter image description here

  • Do you know why it must be this way? – Jonathan Komar Mar 27 '15 at 15:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.