1

I have a box-and-pointer diagram but it looks wrong, because the circular arrowheads are tangential to the point it connects, rather than concentric to that point.

How can I fix this?

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows}
%%%<
\usepackage{verbatim}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{5pt}%
%%%>
\title{immutable list}
\begin{document}
\begin{tikzpicture} 
  \tikzstyle{square} = [draw, shape=rectangle, minimum height=1cm, minimum width=1cm, node distance=2cm, line width=1pt]
  \node[square] (1a) at (0,0)     {};
  \node[square] (1b) at (1cm,0)   {};

  \node[square] (2a) at (3cm,0)   {};
  \node[square] (2b) at (4cm,0)   {};

  \node[square] (3a) at (6cm,0)   {};
  \node[square] (3b) at (7cm,0)   {};

  \node[square] (4a) at (9cm,0)   {};
  \node[square] (4b) at (10cm,0)  {};

  \node (1) at (0,-2) {1};
  \node (2) at (3,-2) {2};
  \node (3) at (6,-2) {3};
  \node (4) at (9,-2) {4};

  \draw [*-latex] (1b.center) -- (2a);
  \draw [*-latex] (2b.center) -- (3a);
  \draw [*-latex] (3b.center) -- (4a);
  \draw (4b.north east) -- (4b.south west);

  \draw [*-latex] (1a.center) -- (1);
  \draw [*-latex] (2a.center) -- (2);
  \draw [*-latex] (3a.center) -- (3);
  \draw [*-latex] (4a.center) -- (4);

\end{tikzpicture}
\end{document}
Jason S
  • 2,838

2 Answers2

5

Getting the required effect is pretty easy using the "old-style" arrows:

\documentclass[tikz,border=5]{standalone}
\pgfarrowsdeclare{dot}{dot}
{
  \pgfarrowsleftextend{0pt}
  \pgfarrowsrightextend{0pt}
}
{
  \pgfpathcircle{\pgfqpoint{0pt}{0pt}}{2pt}
  \pgfusepathqfill
}
\begin{document}
\begin{tikzpicture}
\draw [help lines] (0,0) grid (3,2);
\draw [dot-stealth, red]  (0,0) -- (3,2);
\end{tikzpicture}
\end{document}

enter image description here

...But it is much easier with the arrows.meta library:

\documentclass[tikz,border=5]{standalone}
\usetikzlibrary{arrows.meta}
\pgfarrowsdeclare{dot}{dot}
{
  \pgfarrowsleftextend{0pt}
  \pgfarrowsrightextend{0pt}
}
{
  \pgfpathcircle{\pgfqpoint{0pt}{0pt}}{2pt}
  \pgfusepathqfill
}
\tikzset{Dot/.tip={Circle[length=4pt,sep=-2pt]}}
\begin{document}
\begin{tikzpicture}
\draw [help lines] (0,0) grid (3,2);
\draw [dot-stealth, red]  (0,0) -- (3,2);
\draw [Dot-Stealth, blue] (0,2) -- (3,0);
\end{tikzpicture}
\end{document}

enter image description here

Mark Wibrow
  • 70,437
  • oh, I like it, but writelatex.com doesn't provide arrows.meta. :-( – Jason S Sep 14 '14 at 17:11
  • @JasonS arrows.meta is only required for the Dot and Stealth arrows. The old-style arrow definition is fine doesn't require this. I've updated the answer to make things a bit clearer. – Mark Wibrow Sep 14 '14 at 17:36
3

If you draw circles at those points, they will centre on the point by default which may be easier than trying to adjust the arrow length:

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

\begin{document}
\begin{tikzpicture}
  [
    square/.style = {draw, shape=rectangle, minimum height=1cm, minimum width=1cm, node distance=2cm, line width=1pt},
  ]
  \node[square] (1a) at (0,0)     {};
  \node[square] (1b) at (1cm,0)   {};

  \node[square] (2a) at (3cm,0)   {};
  \node[square] (2b) at (4cm,0)   {};

  \node[square] (3a) at (6cm,0)   {};
  \node[square] (3b) at (7cm,0)   {};

  \node[square] (4a) at (9cm,0)   {};
  \node[square] (4b) at (10cm,0)  {};

  \node (1) at (0,-2) {1};
  \node (2) at (3,-2) {2};
  \node (3) at (6,-2) {3};
  \node (4) at (9,-2) {4};

  \foreach \i / \j in {1b/2a,2b/3a,3b/4a,1a/1,2a/2,3a/3,4a/4}
  {
    \draw [-latex] (\i.center) -- (\j);
    \path [fill] (\i.center) circle (1.5pt);
  }

  \draw (4b.north east) -- (4b.south west);


\end{tikzpicture}
\end{document}

circles and arrows

Alternatively, you could shorten the start point of the arrow by the radius of the circle. Roughly:

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

\begin{document}
\begin{tikzpicture}
  [
    square/.style = {draw, shape=rectangle, minimum height=1cm, minimum width=1cm, node distance=2cm, line width=1pt},
  ]
  \node[square] (1a) at (0,0)     {};
  \node[square] (1b) at (1cm,0)   {};

  \node[square] (2a) at (3cm,0)   {};
  \node[square] (2b) at (4cm,0)   {};

  \node[square] (3a) at (6cm,0)   {};
  \node[square] (3b) at (7cm,0)   {};

  \node[square] (4a) at (9cm,0)   {};
  \node[square] (4b) at (10cm,0)  {};

  \node (1) at (0,-2) {1};
  \node (2) at (3,-2) {2};
  \node (3) at (6,-2) {3};
  \node (4) at (9,-2) {4};

  \foreach \i / \j in {1b/2a,2b/3a,3b/4a,1a/1,2a/2,3a/3,4a/4}
  {
    \draw [*-latex, shorten <=-2pt] (\i.center) -- (\j);
  }

  \draw (4b.north east) -- (4b.south west);


\end{tikzpicture}
\end{document}

shortened arrows

But the adjustment would need to be tweaked to get this exactly right.

For example:

\documentclass[tikz, border=5pt]{standalone}
\usetikzlibrary{arrows.meta}

\begin{document}
\begin{tikzpicture}
  [
    square/.style = {draw, shape=rectangle, minimum height=1cm, minimum width=1cm, node distance=2cm, line width=1pt},
  ]
  \node[square] (1a) at (0,0)     {};
  \node[square] (1b) at (1cm,0)   {};

  \node[square] (2a) at (3cm,0)   {};
  \node[square] (2b) at (4cm,0)   {};

  \node[square] (3a) at (6cm,0)   {};
  \node[square] (3b) at (7cm,0)   {};

  \node[square] (4a) at (9cm,0)   {};
  \node[square] (4b) at (10cm,0)  {};

  \node (1) at (0,-2) {1};
  \node (2) at (3,-2) {2};
  \node (3) at (6,-2) {3};
  \node (4) at (9,-2) {4};

  \foreach \i / \j in {1b/2a,2b/3a,3b/4a,1a/1,2a/2,3a/3,4a/4}
  {
    \draw [{Circle[length=4pt]}-latex, shorten <=-2pt] (\i.center) -- (\j);
  }

  \draw (4b.north east) -- (4b.south west);


\end{tikzpicture}
\end{document}

will give you circles with radius of 2pt (diameter 4pt) which will be centred if you shorten the arrow by 2pt.

adjusted circles

cfr
  • 198,882
  • I like that second suggestion. How do I choose the circle size in these arrowheads? I would like to adjust them anyway. – Jason S Sep 14 '14 at 00:50
  • @JasonS I would look at arrows.meta in the TiKZ manual for the options. I don't know how to adjust them for the arrows library. (I've not yet figured out how the two relate to each other and started with arrows.meta have just learnt that one.) Hang on. – cfr Sep 14 '14 at 00:53
  • writelatex.com doesn't seem to support arrows.meta, just the plain arrows library. – Jason S Sep 14 '14 at 00:54
  • @JasonS Hmmm. Maybe they are using an older version of TiKZ? That's a shame as 3.0.0 introduces a lot of useful features. I'm afraid my TiKZ manual doesn't cover the old arrows library as far as I can tell. – cfr Sep 14 '14 at 01:04
  • screw it, i'm designing my own arrowhead :-( https://stuff.mit.edu/afs/athena/contrib/tex-contrib/beamer/pgf-1.01/doc/generic/pgf/version-for-tex4ht/en/pgfmanualse24.html – Jason S Sep 14 '14 at 01:16
  • @JasonS ;) Try to find out which version of TiKZ you are using first, though. That information appears to be for 1.01 which is rather old. \pgfversion will tell you if you put it into your document. – cfr Sep 14 '14 at 01:20