3

I am drawing two nodes and an arrow between these nodes with

\documentclass[tikz,border=5pt]{standalone}

\usetikzlibrary{positioning}

\begin{document}

\begin{tikzpicture}[node distance=5cm]

% nodes
\node [draw] (A) {A};
\node [draw, right=of A] (B) {B};

% arrows
\draw [->] (A) -- node [above, midway] {Some text} (B);

\end{tikzpicture}

\end{document}

Using \draw [->] (A) -- node [above, midway] {Some text} (B); I can write text above the arrow; however, the text doesn't respect the configured node distance. Can I set the distance between the arrow and the text?

  • 1
    Jamgreen: Nice MWE ;). – cfr Jun 23 '15 at 7:19
4

You will have to shift the label. They are not controlled by the node distance.

Chose one approach:

% arara: pdflatex

\documentclass[tikz,border=5pt]{standalone}
\usetikzlibrary{positioning}

\begin{document}    
    \begin{tikzpicture}[node distance=5cm]
    \node [draw] (A) {A};
    \node [draw, right=of A] (B) {B};
    \node [draw, right=of B] (C) {C};
    \node [draw, right=of C] (D) {D};
    \draw [->] (A) -- node [above=5cm] {Some text} (B); 
    \draw [->] (B) -- node [label={[yshift=5cm]Some text}] {} (C);  
    \draw [->] (C) -- node [label={[label distance=5cm]90:Some text}] {} (D);   
    \end{tikzpicture}   
\end{document}

The one you like, you might apply be adding e.g. \begin{tikzpicture}[every label/.append style={above=5cm}]

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.