0
\documentclass[tikz, border=1cm]{standalone}
\begin{document}

\begin{tikzpicture}
    \node[draw, circle, minimum size=2cm] (c) at (0, 0){};
    \draw[->] (-1, 2)--(1, 2);
\end{tikzpicture}

\end{document}

enter image description here

I placed the arrow above the circle as centered for I could easily "calculate" the coordinates. Is it possible to produce the same arrow in the manner of: draw a "x cm" line with an arrowhead above of "c"?

I tried pic approach but it was needlessly complicated and has limited capabilities with respect to node (such a placing label with respect to pic). I would think the other approach may be defining an a line with an arrow as a predefined shape (which I am still not good at). Is there any other straightforward approach?

  • Maybe I'm missing something, but it seems to me that what you ask for can be achieved simply by storing the radius of the circle in a length and using it in the coordinates of the arrow. – Alice M. Jul 31 '17 at 12:12
  • Please make your MWE compilable for others – daleif Jul 31 '17 at 12:20
  • Since you are using a circular node for the circle, you can access coordinates on the circle, for example (c.north) etc. The line can be build from these coordinates plus the tikz calc lib. – daleif Jul 31 '17 at 12:25
1

One more version:

\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\newcommand\MyCenterArrow[4][]{%[pass to \draw]{node}{above}{length}
  \draw[->,#1]($(#2)+(-#4/2,#3)$) -- +(#4,0);
}
\begin{document}
\begin{tikzpicture}
  \node[draw,circle,minimum size=2cm](a){A};
  \MyCenterArrow{a}{2cm}{1cm}
  \node[draw,minimum size=2cm](b) at (3,0) {B};
  \MyCenterArrow{b}{2cm}{3cm}  
  \MyCenterArrow[red]{b}{-2cm}{2cm}
  \MyCenterArrow[green,-latex]{$(a)!0.5!(b)$}{-1.5cm}{2cm}
\end{tikzpicture}
\end{document}

enter image description here

3

You could use the calc library of tikz and use (c.west) to get the left side of the node and (c.east) for the right side. The result is the same.

\documentclass[tikz, border=1cm]{standalone}
\usetikzlibrary{calc}

\begin{document}

\begin{tikzpicture}
    \node[draw, circle, minimum size=2cm] (c) at (0, 0){};
    \draw[->] ($(c.west)+(0,2)$)--($(c.east)+(0,2)$);
\end{tikzpicture}

\end{document}
  • Note that when using a node to draw a circle instead of the circle directive, you have to be careful with the value of the inner sep (or inner xsep and inner ysep) propertie, that might screw up the size of the circle. And you can get rid of the calc library by using something like \draw (c.west) ++(0, 2) edge[->] ++(2, 0);. – Alice M. Jul 31 '17 at 12:40
3

A simple shift can do the job:

\draw[->] ([shift={(-`half length`,`separation`)}]c.north)--++(0:`total length`);

Some examples:

\documentclass[tikz, border=1cm]{standalone}
%\input{preamble}
\begin{document}

\begin{tikzpicture}
    \node[draw, circle, minimum size=2cm] (c) at (0, 0){};
    \draw[->] ([shift={(-1cm,1.5cm)}]c.north)--++(0:2cm);
    \draw[->] ([shift={(-1.5cm,1.2cm)}]c.north)--++(0:3cm);
    \draw[->] ([shift={(-.5cm,.5cm)}]c.north)--++(0:1cm);
\end{tikzpicture}

\end{document}

enter image description here

2

This macro draws a circle and an arrow above.

\documentclass[tikz, border = 1cm]{standalone}

\begin{document}

% #1    x of circle.
% #2    y of circle.
% #3    Radius of circle.
\newcommand{\allyourstuff}[3]{%
    \draw (#1, #2) circle (#3);
    \draw[->] (#1 - #3, #2 + #3 + 2ex) -- ++(2 * #3, 0);
}

\begin{tikzpicture}
    \allyourstuff{1cm}{0cm}{0.5cm}
    \allyourstuff{12mm}{-20mm}{10mm}
\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.