Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm trying to fix the following TikZ figure, where the circle device in the middle should be embraced by two bended arrows pointing counter-clockwise.

figure with broken orientation for arrows

I have drawn these arrows with an arc path, but the tips of the arrows are unexpectedly both pointing upward. Any idea how to get these arrow tips to follow the direction of the arc?

Here is my code for the above figure:

\documentclass[12pt]{article}

\usepackage{tikz}
\usetikzlibrary{arrows}
\usetikzlibrary{calc}

\begin{document}
\begin{tikzpicture}

 \draw (0,0) circle (1cm);

 \draw[fill=gray!20]  (23:0.45cm)
    -- (23:1cm) arc[radius=1, start angle=23, end angle=-203] (157:1cm)
    -- (157:0.45cm) arc[radius=0.45, start angle=157, end angle=23] (23:0.45cm);

 \draw[fill] (0,0) circle(2pt);

 \draw[->,>=stealth',semithick] (150:1.2cm) arc[radius=1.2, start angle=150, end angle=210] (210:1.2cm);
 \draw[->,>=stealth',semithick] (-30:1.2cm) arc[radius=1.2, start angle=-30, end angle=30] (30:1.2cm);

 \foreach \x/\y in {1/0,2/0,3/0,4/1,5/1,6/1,7/0,0/1}
    \node[rotate={\x*45-90}] at ($(0,0)!.75!\x*45:(1,0)$) {\y} ;
\end{tikzpicture}
\end{document}
share|improve this question
add comment

3 Answers 3

up vote 21 down vote accepted

That is due to the fact that you are adding the final coordinate. They should not be there. Simply change the lines to:

\draw[->,>=stealth',semithick] (150:1.2cm) arc[radius=1.2, start angle=150, end angle=210];
\draw[->,>=stealth',semithick] (-30:1.2cm) arc[radius=1.2, start angle=-30, end angle=30];

This problem arises in far simpler situations as well, it is not inherent to the curve. Consider for example \draw[->] (0,0) -- (2,0) (2,0); which will give an upward pointing arrow on the end of a horizontal line. Basically the new coordinate begins a new path segment and only the last segment of the path is given the arrowtip.

share|improve this answer
    
Thank you, that was it. –  adl Dec 12 '11 at 15:19
add comment

I agree with wh1t3, the problem comes from the path. The path in gray is also delimited in a strange way. It's not a problem of syntax, the syntax radius=..., start angle=..., end angle=... is fine but the shorter syntax is often (always) preferred. The other syntax uses arc [...] like edge[...] and it is tempting to follow the brackets by a node (...).

Here a code more concise but it is not because a code is more concise than another it is always best. And your case, you can avoid \x/\y.

\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{arrows,calc}

\begin{document}
\begin{tikzpicture}
  \draw[fill=gray!20](23:0.45cm) arc (23:157:0.45cm) -- (157:1cm) arc(157:383:1cm)--cycle ;
  \draw[->,>=stealth',semithick] (150:1.2cm) arc (150:210:1.2cm);
  \draw[->,>=stealth',semithick] (-30:1.2cm) arc (-30:30:1.2cm);    
  \foreach \y[count=\x from -1] in {0,0,0,1,1,1,0,1} 
       \node[rotate={\x*45}] at (45*\x+90:0.75cm) {\y} ;
  \draw[fill] (0,0) circle(2pt);  
  \draw (0,0) circle (1cm);  
\end{tikzpicture}
\end{document}
share|improve this answer
1  
You disagree with the TikZ manual on which form is preferred, but your logic is convincing. The arc operation is confusing because it starts at the current point but is centered at a point that is only implicitly specified by the parameters, and ends at an implicit point as well, so that after using it, the current point was never actually written anywhere. With the short form, at least if you are arcing around the center of coordinates, the second parenthetical group does tell you the coordinates of the end point. –  Ryan Reich Dec 12 '11 at 19:08
    
I disagree ... I'm not sure; T.Tantau in the first tutorial uses arc (0:30:3mm);. The new syntax is recent and I use from long time the old syntax. Tantau uses the new syntax only in the index :) –  Alain Matthes Dec 12 '11 at 19:30
    
I guess I'd prefer a syntax something like (p) arc [center = c] (q), or if you want to give the angle, (p) arc [start angle = a, end angle = b] (q) (the center can be inferred from this). Or even just the radius: (p) arc [radius = r, (swap?)] (q), since knowing the radius there are only two positions for the center, and therefore the arc would go either "left" of the straight line or "right" of it, just like a node placed with auto. I do agree with Tantau that the keywords are more expressive than the short form. –  Ryan Reich Dec 12 '11 at 19:50
    
Thank you for the count= trick. I didn't know about this syntax. –  adl Dec 12 '11 at 21:33
add comment

The problem arises due to the path direction not being explicitly calculated with the curve when you use the arc[radius=1, start angle=23, end angle=-203] (150:210:1.2cm) notation. This is due to the reasoning given by wh1t3, instead use the shorter, and which gives you the correct path and arrow:

\draw[->,>=stealth',semithick] (150:1.2cm) arc (150:210:1.2cm);
\draw[->,>=stealth',semithick] (-30:1.2cm) arc (-30:30:1.2cm);
share|improve this answer
2  
This does solve the problem. For the same reason as my solution does. It does not have the final coordinate. I don't know what you mean when you say "the path not being explicitly calculated with the curve", could you elaborate on that? –  Roelof Spijker Dec 12 '11 at 15:18
2  
Actually the TikZ manual seems to recommend against this shorter syntax. It says "There also exists a shorter syntax for the arc operation [...] However, this syntax is harder to read, so the normal syntax should be preferred instead." (Yet the manual is full of examples with the shorter syntax.) –  adl Dec 12 '11 at 15:20
    
@wh1t3 it was due to your reasoning that the final path direction was not calculated, sorry for the misunderstanding in the question at hand, i have corrected the answer –  zeroth Dec 12 '11 at 21:58
    
@adl yes, however it is a matter of what is the easiest for yourself to do. The single argument against is is harder to read. However I find it pretty self-explanatory. Maybe because i have gotten used to it. I do not know. But you should not do what i said, just because i said it. Do what you feel most comfortable doing! :) –  zeroth Dec 14 '11 at 21:03
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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