I want to use the o- arrow in TikZ to highlight certain points in a picture and assign a label to them. Here is an MWE:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows}
\begin{document}

\begin{tikzpicture}
  \node at (0,0) {+};
  \draw[o-,red] (0,0) -- (1,1) node[above] {some label};
\end{tikzpicture}

\end{document}

it produces following output:

point with label - wrong

However, I want something like this:

point with label - correct

I have achieved the correct solution by using

\draw[o-,red, shorten <= -2.3pt] (0,0) -- (1,1) node[above] {some label};

which works fine, but, however, this is not a good solution since if I change e.g. the size of the arrowhead or the line width, things break apart and I have to figure out the correct shorten value again. Plus it is not very accurate and it is cumbersome to find the correct shorten value. It would be more practical if the anchor of the o- arrow in Tikz is at the centre of the circle. How can I achieve that?

Peter Grill's answer is the way to go, I'd say. This here is just to show you some options, and also to mention that the arrows library has been superseded by arrows.meta.

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\begin{document}

\begin{tikzpicture}
  \node[outer sep=0pt] (plus) at (0,0) {+};
  \draw[{Circle[open,width=width("+"),length=width("+")]}-,red,shorten <={-1/2*width("+")}] (plus.center) -- (1,1) node[above] {some label};
\end{tikzpicture}

\end{document}

enter image description here

  • What if there is no node, but only a coordinate where I want to place the circle? like \draw[{Circle[open]}-,red] (0,0) -- (1,1) node[above] {some label}; and I want the circle to be around coordinate (0,0). – T. Pluess Sep 21 at 7:30
  • @T.Pluess If you replace (plus.center) by (0,0), you obtain exactly the same picture. – marmot Sep 21 at 7:34
  • sure. I just realized that. It was not obvious at first! – T. Pluess Sep 21 at 7:42
  • @T.Pluess I should perhaps have kept (0,0) but I am a fan of having not too many explicit coordinates around, so I do such things sort of subconsciously. ;-) – marmot Sep 21 at 7:46

One way would be to not use the o- arrow style and draw the circle with the when you create the \node:

\node [circle, draw=red, inner sep=-1pt] (Plus Sign) at (0,0) {+}

Here, I have named this node (Plus Sign) so that we can draw the line to this node without having to respecify the coordinate:

\draw[-,red] (Plus Sign) -- (1,1) node[above] {some label};

enter image description here

Alternatively you could use a pin:

enter image description here

Code:

\documentclass[border=1pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows}
\begin{document}

\begin{tikzpicture}
  \node [circle, draw=red, inner sep=-1pt] (Plus Sign) at (0,0) {+};
  \draw[-,red] (Plus Sign) -- (1,1) node[above] {some label};
\end{tikzpicture}

\end{document}

Code: pin

\documentclass[border=1pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\begin{document}

\begin{tikzpicture}
  \node  (Plus Sign) at (0,0) {+};
  \node [circle, draw=red, inner sep=1pt, pin={[pin edge={red, thin}, pin distance=1.4cm, pin position=45, text=red] {some label}}] at (Plus Sign)  {};
\end{tikzpicture}
\end{document}
  • sure, but the plus sign was just an example. Often, I don't have a specific node, but some arbitrary coordinates where I want to put a label. – T. Pluess Sep 21 at 7:15
  • @T.Pluess: IN that case, I think perhaps you should use a pin instead of an arrow. – Peter Grill Sep 21 at 7:35

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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