4

Possible Duplicate:
Draw arc in tikz when center of circle is specified

an very trivial question but I can't do it! Sorry but I find coordinates confusing.

I would like to draw an arc around a circle; both should have the same center of rotation. And I want to position the arc relative to the circle.

Here is the MWE to correct:

\documentclass{article}
\usepackage{tikz}
\usepackage{graphicx}

\tikzset{state/.style={circle,draw=black, very thick,minimum size=4em}}

\begin{document}
\begin{tikzpicture}
\node[state, fill=black!20] (sh1) at (1,3) {Circle};
\draw[thick] (sh1) arc (0:300:2cm);
\end{tikzpicture}
\end{document}

How do I get to have the same center for both shapes, with relative positioning of the arc? Any simple and brilliant idea?

marked as duplicate by Jake, percusse, Loop Space, Tom Bombadil, lockstep Aug 30 '12 at 16:00

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • You can replace your \draw ... command with \draw[thick] (sh1) ++(0:2cm) arc (0:300:2cm); to move to a point on the circle before drawing the arc. See Leo Liu's answer to Draw arc in tikz when center of circle is specified – Jake Aug 30 '12 at 11:14
  • Thanks Jake. I did have a look at the post you mention before posting mine but I could not make the code work. I am not familiar with this way of coding. – jejuba Aug 30 '12 at 12:42
  • No problem. It's always a good idea to include the things you've tried and the questions you've already looked at in your question. That way, people will be able to offer more specific advice. – Jake Aug 30 '12 at 12:45
7

The problem is that for arc you specify the start point of the arc, not the cirle's center. You could define a custom command like this:

The Code

\documentclass{article}
\usepackage{tikz}


\tikzset{state/.style={circle,draw=black, very thick,minimum size=4em}}

\def\centerarc[#1] (#2) (#3:#4:#5)% [draw options] (center) (initial angle:final angle:radius)
{ \draw[#1] (#2) ++(#3:#5) arc (#3:#4:#5);
}

\begin{document}
\begin{tikzpicture}
\node[state, fill=black!20] (sh1) at (1,3) {Circle};
\centerarc[thick] (sh1) (0:300:2cm)
\end{tikzpicture}
\end{document}

Special thanks to Paul Gaborit and Jake for simplifying this.

The Result

enter image description here

  • 1
    To specify the start point, the following notation is simpler: ($(#2) + (#3:#5)$)... – Paul Gaborit Aug 30 '12 at 11:29
  • @Jake, thanks, just saw that, I will update. – Tom Bombadil Aug 30 '12 at 11:34
  • Well, just great! – jejuba Aug 30 '12 at 12:50
4

Well, I don't a have brilliant idea ... but note, that arc always starts at given coordinate - in your case at the center of the circle sh1, and its center is shifted by the amount specified in last argument for arc - in your case by 2cm. So, if you shift the start of the arc in the appropriate direction and amount, you will get what you desired (if I understand your problem correctly).

In your case try:

\documentclass{article}
\usepackage{tikz}
\usepackage{graphicx}

\tikzset{state/.style={circle,draw=black, very thick,minimum size=4em}}

\begin{document}
\begin{tikzpicture}
\draw[help lines] (-3,-3) grid + (9,9);
\node[state, fill=black!20] (sh1) at (1,3) {Circle};
\draw[thick] ([xshift=20mm] sh1.center) arc (0:300:2cm);
\end{tikzpicture}
\end{document}
  • Thanks Zarko. It works well. The only (minimal) issue I see is that if I change the angles in the arc, the arc and the circle do not share automatically the same center of rotation. But this can be remedied. Thanks again. – jejuba Aug 30 '12 at 12:52

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