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.

Consider the slight modification of the construction from the solution to this question: Variables and basic arithmetics and tikz-euclide

\documentclass{minimal}
\usepackage{tkz-euclide}
\begin{document}

\begin{tikzpicture}[scale=3]
\tkzDefPoint(0,0){O}
\tkzDrawCircle[R](O,1 cm)
\def\sectors{20}
\foreach \i in {1,2,...,\sectors} {
    \tkzDefPoint({\i*360/\sectors}:1){P\i}   
    \tkzDrawSegment[color=black](O,P\i)
    \tkzLabelPoint(P\i){\i} %modified here!
}
\end{tikzpicture}
\end{document}

This gives me the following output:

enter image description here

Now my question is, if it is possible to position the labels in extension of the radial lines.

Is it possible to rotate the labels additionally corresponding to the orientation of the respective radial line? (so that for example the 5 on my output would be rotated by 90° counter-clockwise).

share|improve this question
add comment

3 Answers

up vote 7 down vote accepted

A friend of mine once needed kind of a cake to visualize fractions. Adding rotated nodes wasn't hard:

\documentclass{scrartcl}
\usepackage{tikz}
\usetikzlibrary{intersections, calc, fpu, decorations.pathreplacing}

\newcommand{\TikZFractionalCake}[5]{% Num, Denom, Color, Borders, Size
    \pgfmathsetmacro{\angle}{360/#2};%
    \foreach \x in {1,...,#1}%
    {   \pgfmathsetmacro{\lox}{\x-1}%
        \filldraw[draw=#4,fill=#3] (0,0) -- (\angle*\lox:#5) arc (\angle*\lox:\angle*\x:#5) -- cycle;%
        \pgfmathsetmacro{\mix}{\x-0.5}%
        \node[rotate=\mix*\angle] at (\mix*\angle:#5+0.3) {\x};
    }
}   

\begin{document}

\begin{tikzpicture}
\TikZFractionalCake{20}{20}{white}{black}{3}
\end{tikzpicture}

\end{document}

enter image description here


Sure, makes it even easier:

\documentclass{scrartcl}
\usepackage{tikz}
\usetikzlibrary{intersections, calc, fpu, decorations.pathreplacing}

\newcommand{\TikZFractionalCake}[5]{% Num, Denom, Color, Borders, Size
    \pgfmathsetmacro{\angle}{360/#2};%
    \foreach \x in {1,...,#1}%
    {   \pgfmathsetmacro{\lox}{\x-1}%
        \filldraw[draw=#4,fill=#3] (0,0) -- (\angle*\lox:#5) arc (\angle*\lox:\angle*\x:#5) -- cycle;%
        \node[rotate=\x*\angle] at (\x*\angle:#5+0.3) {\x};
    }
}   

\begin{document}

\begin{tikzpicture}
\TikZFractionalCake{20}{20}{white}{black}{3}
\end{tikzpicture}

\end{document}

enter image description here


That is possible indeed:

\documentclass{scrartcl}
\usepackage{tikz}
\usetikzlibrary{intersections, calc, fpu, decorations.pathreplacing}

\newcommand{\TikZFractionalCake}[6]{% Num, Denom, Color, Borders, Size, k-th label
    \pgfmathsetmacro{\angle}{360/#2};%
    \foreach \x in {1,...,#1}%
    {   \pgfmathsetmacro{\lox}{\x-1}%
        \filldraw[draw=#4,fill=#3] (0,0) -- (\angle*\lox:#5) arc (\angle*\lox:\angle*\x:#5) -- cycle;%
    }
    \pgfmathsetmacro{\secondstep}{2*#6}
    \pgfkeys{/pgf/number format/.cd,int detect,precision=2}
    \foreach \x in {#6,\secondstep,...,#1}%
    {   \node[rotate=\x*\angle] at (\x*\angle:#5+0.3) {\pgfmathprintnumber{\x}};
    }
}   

\begin{document}

\begin{tikzpicture}
\TikZFractionalCake{21}{21}{white}{black}{3}{3} 
\end{tikzpicture}

\end{document}

enter image description here

share|improve this answer
    
Great. Is it possible to have the numbers in extension of the radial lines as in Werners first image? –  student Oct 19 '11 at 18:35
    
Thanks. Is it also possible to label only every second or more generally every k'th point? –  student Oct 19 '11 at 19:22
    
Hmm, probably none of the tikzlibraries are actually needed, this is due to copy and paste from an old project. –  Tom Bombadil Oct 19 '11 at 20:03
add comment

As a typical counterpart to tikz drawings, here's a take on the pstricks version.

enter image description here

\documentclass{article}
\usepackage{pst-node}% http://ctan.org/pkg/pst-node
\usepackage{multido}% http://ctan.org/pkg/multido
\begin{document}

\begin{pspicture}(10,10)
  \SpecialCoor
  \psset{unit=3cm,runit=3cm}% Scaling of x,y and r units
  \pnode(3,0){O}% Circle origin
  \pscircle(O){1}% Outer circle
  \degrees[20]% 20 angles per 360 degrees (each angle is 18 degrees)
  \rput(O){\multido{\i=1+1}{20}{% Cycle through 20 angles and relocate relative to circle origin
    \pcline(O)(1;\i)% Print line from origin to circle edge
    \uput{5pt}[\i]{\i}(1;\i){\i}% Print label with rotation
  }}
\end{pspicture}
\end{document}

Modifying the label command to

\uput{5pt}[\i]{0}(1;\i){\i}% Print label without rotation

yields

enter image description here

Printing labels at for every odd index is possible by using

\ifodd\i\uput{5pt}[\i]{\i}(1;\i){\i}\fi% Print ODD label with rotation

while

\ifodd\i\else\uput{5pt}[\i]{\i}(1;\i){\i}\fi% Print EVEN label with rotation

prints only even indices. Here's an illustration of the latter (print EVEN labels with rotation) choice:

enter image description here

This can be combined with no rotation of every node as well. For this modify the appropriate parameter in the \uput command, which is defined by

\uput{<labelsep>}[<refangle>]{<rotation>}(<coordinate>){<stuff>}

This rotates <stuff> by angle <rotation> at distance <labelsep> and angle <refangle> from <coordinate>. In my example, using \degrees[<n>] divides 360 degrees into <n> angles. So, it allows you to use these angles (as numbers, where angle=i*(360/<n>)). Also, because of \SpecialCoor, one can use polar coordinates - represented by (<r>;<t>) - or Cartesian coordinates - represented by (<x>,<y>). pst-node allows for substituting any of these <coordinate> types with a node <name> defined by (say) \psnode(<coordinate>){<name>}, as was done in the MWE.

share|improve this answer
    
Thanks. Is it also possible to label only every second point? –  student Oct 19 '11 at 18:14
    
@user4011: I've updated my answer to reflect the possibility to label every other point (even or odd). Other expansions based on similar conditioning is also possible. –  Werner Oct 19 '11 at 19:23
add comment

You have several solutions :

1) you can mix tkz-euclide with tikz

\documentclass{minimal}
\usepackage{tkz-euclide}
\begin{document}

\begin{tikzpicture}[scale=1]
\tkzDefPoint(0,0){O}
\tkzDrawCircle[R](O,3 cm)
\def\sectors{20}
\foreach \i in {1,2,...,\sectors} {
    \tkzDefPoint({\i*360/\sectors}:3){P\i}    
    \tkzDrawSegment[color=black](O,P\i)
      \node[label=18*\i:\i] at  (P\i) {} ;
}
\end{tikzpicture}
\end{document}  

enter image description here

\end{document} 

3) you use only tikz ! (see Tom' solution)

4) I forgot this one ( I have some difficulties to work with my personal packages). I put like you scale=3 but when it's possible I avoid the use of scale.

\documentclass{minimal}
\usepackage{tkz-euclide}
\begin{document}

\begin{tikzpicture}[scale=3]
\tkzDefPoint(0,0){O}
\tkzDrawCircle[R](O,1 cm)
\def\sectors{20} 
\tikzset{label style/.style={} }; 
\foreach \i in {1,2,...,\sectors} {
    \tkzDefPoint({\i*360/\sectors}:1){P\i} 
    \tkzDrawSegment[color=black](O,P\i)
      \tkzLabelPoint[label=360/\sectors*\i:\i](P\i){}
}
\end{tikzpicture}
\end{document}

5) It's possible to place the label on the radius but I think it's not a good typographic idea

\documentclass{minimal}
\usepackage{tkz-euclide}
\begin{document}

\begin{tikzpicture}[scale=3]
\tkzDefPoint(0,0){O}
\tkzDrawCircle[R](O,1 cm)
\def\sectors{20} 
\tikzset{label style/.style={} }; 
\foreach \i in {1,2,...,\sectors} {
    \tkzDefPoint({\i*360/\sectors}:1){P\i} 
    \tkzDrawSegment[color=black](O,P\i)
} 
% it's possible to avoid the next loop with conditional macro ...
\foreach \i in {1,3,...,\sectors} {% you can change what you want here
            \tkzLabelPoint[rotate=18*\i,right](P\i){\i} ;
}  
\end{tikzpicture}
\end{document} 

enter image description here

share|improve this answer
    
Better is ` \node[label=360/\sectors*\i:\i] at (P\i) {} ; ` –  Alain Matthes Oct 19 '11 at 18:43
    
In your first solution the some positions are fine, others are not so good, for example 7 is good, 11 is not so good. Is it possible to fine-control the radial position of the labels? –  student Oct 19 '11 at 18:54
    
@user4011 Yes with the first solution or with the last one (5). You can do what you want with label=and it's possible to add an option : tkzLabelPointis like \node with only a default style. The second solution is a bad one because I forgot how to remove the default style above=-6t is ugly ! –  Alain Matthes Oct 19 '11 at 19:09
    
@user4011 Sloped labels are not a good idea. It's more difficult to read and to analyse graph like this. There are some confusions like 6 and 9 –  Alain Matthes Oct 19 '11 at 21:24
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.