how to make a cog/gear in LaTeX?

I was wondering what would be a good way to make this in LaTeX. Basically, what I want to do with this is use it as a chapter heading. So basically it will be something like this:

cog chapter # Chapter name


What would be the best way to achieve this? Am I better off using the image or making it myself?

Thanks a lot for you time!

EDIT: I have done what the comments have recommended but I am having difficult implementing the gear into the chapter heading using titlesec. Here is the MWE:

\documentclass[12pt]{memoir}

\usepackage{tikz}
\usepackage{titlesec}

% #1 number of teeths
% #4 angle from start to end of the first arc
% #5 angle to decale the second arc from the first

\newcommand{\gear}[5]{%
\foreach \i in {1,...,#1} {%
[rotate=(\i-1)*360/#1]  (0:#2)  arc (0:#4:#2) {[rounded corners=1.5pt]
-- (#4+#5:#3)  arc (#4+#5:360/#1-#5:#3)} --  (360/#1:#2)
}}

\titleformat{\chapter}{\Huge\bfseries}{\usebox{\gear{18}{0.5}{0.4}{10}{2}}\thechapter}{20pt}{\Huge\b‌​fseries}

\begin{document}
\begin{tikzpicture}
\draw[thick] \gear{18}{0.5}{0.4}{10}{2};
\end{tikzpicture}

\chapter{Whatever}

\end{document}


EDIT 2: With the help of @Qrrbrbirlbel and @StefanKottwitz I have gotten the following:

\documentclass[12pt]{memoir}

\usepackage{tikz}
\usepackage{titlesec}

\newsavebox\gearbox
\newcommand{\gear}[5]{%
\begin{tikzpicture}
\draw[ultra thick]
\foreach \i in {1,...,#1} {%
[rotate=(\i-1)*360/#1]  (0:#2)  arc (0:#4:#2) {[rounded corners=1.5pt]
-- (#4+#5:#3)  arc (#4+#5:360/#1-#5:#3)} --  (360/#1:#2)
};\end{tikzpicture}}
\sbox\gearbox{\resizebox{!}{2em}{\gear{18}{2}{1.6}{10}{2}}}
\titleformat{\chapter}{\Huge\bfseries}{\usebox{\gearbox}\thechapter}{20pt}{\Huge\bfseries}

\begin{document}

\chapter{Whatever}

\end{document}


But I would like to have the gear look more like this and have the gear behind the chapter number. How can this be done?

• There you go: Creating gears in TikZ – Qrrbrbirlbel Mar 4 '13 at 22:03
• @Qrrbrbirlbel, oh wow. Okay. How can I implement this into the chapter heading? – Jeel Shah Mar 4 '13 at 22:04
• Most likey with the titlesec package. Take a look at Book layout Contents, Chapter, Section,. What class are you using? – Qrrbrbirlbel Mar 4 '13 at 22:15
• @Qrrbrbirlbel I am using the memoir package – Jeel Shah Mar 5 '13 at 0:32
• If you can find out how to make the gear smaller (tikz is beyond me), stick the picture in a \newsavebox{\gear} and use \titleformat{\chapter}{\Huge\bfseries}{\usebox{\gear}\thechapter}{20pt}{\Huge\bfseries} in your preamble. (using titlesec, of course.) (20pt here is arbitrary, but a value is required.) – Sean Allred Mar 6 '13 at 19:54

Before you can use the box, you need to store your gears within, such as

\newsavebox{\chaptergear}
\savebox{\chaptergear}{%
\begin{tikzpicture}
\draw[thick] \gear{18}{0.5}{0.4}{10}{2};
\end{tikzpicture}}
\titleformat{\chapter}{\Huge\bfseries}{\usebox{\chaptergear}%
\thechapter}{20pt}{\Huge\bfseries}


Here is a quick gear construction with a single path so you can fill it properly. I will try to come back to this to make it with a proper key=value syntax. Right now it's only boring \definitions. But if you have a different thread profile the idea is essentially the same.

\documentclass[tikz]{standalone}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\def\teethnumber{17}     %<--- How many teeth
\draw[fill=gray,even odd rule]
let
\n{dpt} = {360/\teethnumber)}%deg per teeth %<--- Overkill! Can be defined outside
in
(0,0) circle (4mm)                          %<--- Shaft circle
({\n{dpt}*(0.5)}:\outrad) \foreach \x in {1,...,\teethnumber}{ %<--- Tooth covers half width
arc ({\n{dpt}*(\x+0.25)}:{\n{dpt}*(\x+0.5)}:\outrad)--%<-- Get to the next one for cont. path
};
\end{tikzpicture}
\end{document}


A few examples starting from the given code

Last one is done by making the shaft circle larger than the outer radius. Which might be beneficial for planet gears and whatnot....

I was using several material: the answer of Stefan Kottwitz here, and the amazing macro of Alain Matthes to create a gear.

Mixed together with a bit of fine tuning it gives something like this:

\documentclass[12pt]{memoir}
\usepackage{tikz}
\usepackage{titlesec}

% #1 number of teeths
% #4 angle from start to end of the first arc
% #5 angle to decale the second arc from the first

\newcommand{\gearmacro}[5]{%
\foreach \i in {1,...,#1} {%
[rotate=(\i-1)*360/#1]  (0:#2)  arc (0:#4:#2) {[rounded corners=1.5pt]
-- (#4+#5:#3)  arc (#4+#5:360/#1-#5:#3)} --  (360/#1:#2)
}}

\newcommand{\chaptergear}{\begin{tikzpicture}
\fill[gray] (0,0) circle (2cm);
\draw[thick,rotate=12,fill=gray] \gearmacro{8}{2}{2.4}{20}{2};
\draw[thick,fill=white] (0cm,0cm) circle(1.35cm);
\end{tikzpicture}}

\newsavebox\gearbox
\sbox\gearbox{\resizebox{!}{5em}{\chaptergear}}
\titleformat{\chapter}{\Huge\bfseries}{\raisebox{-0.75cm}{\usebox{\gearbox}}\hspace*{-1.25cm}\thechapter\vspace{\stretch{-10}}}{45pt}{\Huge\bfseries}

\begin{document}
\chapter{Whatever2}
\end{document}


Which gives you

I have to admit that I am not very happy with the manual tuning for putting the chapternumber in the middle of the gear, but unfortunately I do not know how to circumvent that.

• For some reason, in my document the numbers within the gear/cog are not centred. I copy pasted the code directly – Jeel Shah Mar 23 '13 at 5:02
• Hmm, I don't understand it. I created the code on my ubuntu system and tested it just now on my Win8 system and in the latter case it gives me exactly the same result. – Dominikus K. Mar 23 '13 at 19:50