# How to add ticks in a circle in TikZ

Referring to the question How to make add tick to node in tikz, how do I extend this to a circle shape in TikZ.

A simple approach is to draw lines as ticks by calculating the coordinates. Sample approach below:

\documentclass[tikz]{standalone}
\usetikzlibrary{calc}

\begin{document}
\begin{tikzpicture}
\node[circle,draw,minimum size=10cm] (a) at (0,0) {};
\draw ($(a.center)-(4.5,0)$) -- (a.west);
\draw ($(a.east)-(0.5,0)$) -- (a.east);
\end{tikzpicture}
\end{document}


But, this approach is not effective, as the ticks length has to calculated manually.

Is there a better approach to do this (ticks in the circle would be like the lines on an alarm clock, which are inclined execept at 12, 3, 6 and 9 numbers).

• If you don't want to calculate tick lengths, use polar coordinates.
– user156344
Mar 30, 2019 at 17:12
• @JolueV that is a manual calculation as well where there is a chance for error or miscalculation. Mar 30, 2019 at 17:14

Use \foreach and polar coordinates (with care of course) you can have this

\documentclass[tikz]{standalone}

\begin{document}
\begin{tikzpicture}
\node[circle,draw,minimum size=10cm] (a) at (0,0) {};
\foreach \i [count=\j] in {60,30,...,-270} {
\draw (\i:5) -- (\i:4.5);
\draw (\i:4.2) node[font=\large] {\j};
}
\end{tikzpicture}
\end{document}


In this code, the for loops iterates through the set {60, 30, 0, −30, −60, −90, −120, −150, −180, −210, −240, −270}. Each of these numbers is the angle of the "ticks". I use polar coordinate based on these iterators, so the angles of the "ticks" are accurate.

I set a counter for the for loop (\j) to add numbers to the picture.

\documentclass[tikz]{standalone}

\begin{document}
\begin{tikzpicture}
\node[circle,draw,minimum size=10cm] (a) at (0,0) {};
\foreach \i [count=\j] in {60,30,...,-270} {
\draw (\i:5) -- (\i:4.5);
\draw (\i:4.2) node[font=\large] {\j};
}
\foreach \i in {84,78,...,-270} \draw (\i:5) -- (\i:4.8);
\end{tikzpicture}
\end{document}


The second for loop is to draw smaller ticks. 84, 78, etc. are the angles of these ticks.

• can you explain the code in the for loop as well please Mar 30, 2019 at 17:27
• @subhamsoni I added some explanations.
– user156344
Mar 30, 2019 at 17:32
• what is \draw (\i:5) -- (\i:4.5) Mar 30, 2019 at 17:35
• @subhamsoni It draws a line joining point (\i:5) and point (\i:4.5); all of them are polar coordinates. Point (x:y) is defined like this.
– user156344
Mar 30, 2019 at 17:41

Something like that?

\documentclass[tikz]{standalone}
\usetikzlibrary{calc}

\begin{document}
\begin{tikzpicture}
\node[circle,draw,minimum size=10cm] (a) at (0,0) {};
\draw ($(a.center)-(4.5,0)$) -- (a.west);
\draw ($(a.east)-(0.5,0)$) -- (a.east);
\foreach \X in {0,10,...,350}
{\draw (a.\X) -- ++ (\X:0.2);}
\end{tikzpicture}
\end{document}


OK, inside.

\documentclass[tikz]{standalone}

\begin{document}
\begin{tikzpicture}
\node[circle,draw,minimum size=10cm] (a) at (0,0) {};
\foreach \X in {0,10,...,350}
{\draw (a.\X) -- ++ (180+\X:0.2);}
\end{tikzpicture}
\end{document}


\foreach \X in {0,10,...,350} loops over \X in {0,10,...,350}, and then the nodes have anchors given in degrees, so (a.\X) is a point at the boundary of a at the angle \X. This syntax is mentioned in my previous answer to one of your questions. ++ (\X:0.2) adds some shift in polar coordinates, \X is the angle and 0.2 the radius. To have the ticks inwards, we need to add 180 degrees to \X (one could also use (\X:-0.2).)

And just for fun: a watch.

\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}[font=\sffamily]
\node[circle,draw,minimum size=10cm] (a) at (0,0) {};