2

Context I would like to draw lines between nodes to indicate a dependence relationship. The nodes are drawn as circles. Unfortunately the arrow is hidden by the circle.

Question How can I shorten the line such that there is a gap between the line and both circles?

Code

\draw [color=black, fill=black] (1.00, 0.00) circle (.1);
\draw [color=black, fill=black] (2.00, 0.00) circle (.1);
\draw (1.00, 1.00);
\draw (2.00, 1.00);
\draw [color=white] (2.25, 1.25) circle (.1);
\path [draw, ->] (1.00, 0.00) -- (2.00, 0.00);
\path [draw, ->] (1.00, 1.00) -- (2.00, 1.00);

Output:

Two lines, headed with an arrow on the right side.

  • 4
    Use actual nodes for the circles. Give these nodes names, and connect them as usual (use their names as coordinates). – Qrrbrbirlbel May 11 '15 at 9:01
  • Like Qrrbrbirlbel, use actual nodes. Also, you don't need to specify (1.00, 2.00) in the coordinates, (1,2) is enough. :D – Alenanno May 11 '15 at 9:04
5

Options shorten > and shorten < can be used to shorten a line or arrow. The following example shortens the arrow at both ends by the radius of the circles and some extra space, e.g. the line width:

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw [color=black, fill=black, radius=.1]
  (1, 0) circle[]
  (2, 0) circle[]
;
\draw [
  ->,
  shorten <=.1cm + \pgflinewidth,
  shorten >=.1cm + \pgflinewidth,
] (1, 0) -- (2, 0);
\draw [->] (1, 1) -- (2, 1);
\end{tikzpicture}
\end{document}

Result

3

While it was being suggested to you in the comments, I was slightly modifying your code to show you that you should have used nodes. The arrow properties can also be set globally in the \tikzpicture options without having to type it in each arrow, by using the Tikz library arrows.meta.

I also think that if you need to draw arrows, you're better off saying \draw ... than \path[draw] ..., which is very useful for drawing invisible paths for calculating coordinates.

Lastly, I'm not sure what the commands in the middle were supposed to do:

\draw (1.00, 1.00);
\draw (2.00, 1.00);
\draw [color=white] (2.25, 1.25) circle (.1);

Except for the circle (not at either side of the arrows), the other commands didn't do anything (if I missed their purpose, let me know).

figure 1

\documentclass[margin=10pt]{standalone}
\usepackage{tikz}

\usetikzlibrary{arrows.meta}

\begin{document}
\begin{tikzpicture}[->] % add ,>=latex or ,>=stealth to change arrow tip

\node [circle, draw, fill=black] (a1) at (1,0) {};
\node [circle, draw, fill=black] (a2) at (2,0) {};

\node [circle, draw, fill=white] (b1) at (1,1) {};
\node [circle, draw, fill=white] (b2) at (2,1) {};

\draw (a1) -- (a2);
\draw (b1) -- (b2);

\end{tikzpicture}
\end{document}
  • Thank you very much for your answer. :) Indeed it's somehow meaningful that connections between nodes are adjusted to the node size. Unfortunately I did not came up with that on my own ;) Actually I really need some more space between line and circle such that I will stick with Heiko's answer. – Christoph May 11 '15 at 9:46
  • 1
    @Christoph Just for your info: you can use shorten also with nodes. See my answer to this question. In case you want to use both things, you can do it. :) – Alenanno May 11 '15 at 9:52

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.