6

I have the following issue: I add a node to a path (drawn with \draw) and I'd like the node to be positioned "midway" or "pos=.5", but, in the following example, the node gets positioned on the first node of the graph (rrhp) and not on the arc. I have done other drawings with the same loaded libraries and there the positioning works, so i'm wondering what's wrong with the code below.

There are many more packages included but they don't seem to have clashes with tikz, i included pgfplots though eliminating it does not solve the issue.

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{shadows,arrows,calc,backgrounds,fit,shapes,snakes,shapes.multipart,decorations.pathreplacing,shapes.misc,patterns,positioning}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}[node distance=4mm]
    \node[align=center] (rrhp) { Robust Relational \\ Hyperproperty Preservation};
    \node[align=center, below = of rrhp.south east] (r2rsp) { Robust 2-Relational \\ Safety Preservation};
    \node[align=center, below = of r2rsp.south, yshift=-3em] (fac2) { Fully Abstract\\ Compilation };

    \draw[-] (rrhp.south) to (r2rsp.north west);
    \draw[-, dotted] (r2rsp.south) to (fac2.north) node [right,align=left,pos=.5] { + determinacy } ;  

\end{tikzpicture}
\end{document}

the "+determinacy" node is misplaced.

1
  • Not an easy thing to search for, but I'm sure this has come up before. You need \draw (a) to node{..} (b);, not \draw (a) to (b) node[midway] {..};. Apr 3 '18 at 13:47
6

It is enough to use the Line-To operation (< coordinate > -- < coordinate >) instead of the To-Path operation (< coordinate > to < coordinate >):

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{shadows,arrows,calc,backgrounds,fit,shapes,snakes,shapes.multipart,decorations.pathreplacing,shapes.misc,patterns,positioning}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}[node distance=4mm]
    \node[align=center] (rrhp) { Robust Relational \\ Hyperproperty Preservation};
    \node[align=center, below = of rrhp.south east] (r2rsp) { Robust 2-Relational \\ Safety Preservation};
    \node[align=center, below = of r2rsp.south, yshift=-3em] (fac2) { Fully Abstract\\ Compilation };

    \draw[-] (rrhp.south) to (r2rsp.north west);
    \draw[-, dotted] (r2rsp.south) -- (fac2.north) node [right,align=left,pos=.5] { + determinacy } ;  

\end{tikzpicture}
\end{document}

Second solution: The syntax of the To-Path operation you used does not match that of the manual (p 157 of 3.0.1.a manual)

 \path ... to[options] < nodes > < coordinate or cycle > ...;

The code is

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{shadows,arrows,calc,backgrounds,fit,shapes,snakes,shapes.multipart,decorations.pathreplacing,shapes.misc,patterns,positioning}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}[node distance=4mm]
    \node[align=center] (rrhp) { Robust Relational \\ Hyperproperty Preservation};
    \node[align=center, below = of rrhp.south east] (r2rsp) { Robust 2-Relational \\ Safety Preservation};
    \node[align=center, below = of r2rsp.south, yshift=-3em] (fac2) { Fully Abstract\\ Compilation };

    \draw[-] (rrhp.south) to (r2rsp.north west);
    \draw[-, dotted] (r2rsp.south) to  node [right,align=left,pos=.5] { + determinacy } (fac2.north);  

\end{tikzpicture}
\end{document}
1
  • extra thanks for the second fix -- you never know when in later updates these changes break things you don't know -- thanks again!!
    – Squera
    Apr 4 '18 at 8:47
3

i would use quotes library and with it slightly simplify the picture code:

\documentclass{article}
\usepackage{pgfplots} % <--- it load `tikz`
\usetikzlibrary{arrows,
                backgrounds,
                decorations.pathreplacing,
                calc,
                fit,
                patterns, positioning,
                quotes, % <--- added
                shadows, shapes, shapes.multipart, shapes.misc, snakes
                }

\begin{document}
\begin{tikzpicture}[node distance=4mm, align=center]
    \node (rrhp) { Robust Relational \\ Hyperproperty Preservation};
    \node [below=of rrhp.south east] (r2rsp) { Robust 2-Relational \\ Safety Preservation};
    \node[below=12mm of r2rsp] (fac2) { Fully Abstract\\ Compilation };
%
    \draw (rrhp.south) -- (r2rsp.north west);          % <--- changed
    \draw[dotted] (r2rsp) to ["+ determinacy"] (fac2); % <--- changed
\end{tikzpicture}
\end{document}

enter image description here

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.