Fancy chapter headings with TikZ
11 October 2008 by Stefan Kottwitz
A question on LaTeX-Community.org inspired me to try pgf/TikZ together with titlesec to produce fancy chapter headings. The result is this small compilable demonstration example:
\documentclass[svgnames]{report} \usepackage{tikz} \usepackage{kpfonts} \usepackage[explicit]{titlesec} \newcommand*\chapterlabel{} \titleformat{\chapter} {\gdef\chapterlabel{} \normalfont\sffamily\Huge\bfseries\scshape} {\gdef\chapterlabel{\thechapter\ }}{0pt} {\begin{tikzpicture}[remember picture,overlay] \node[yshift=-3cm] at (current page.north west) {\begin{tikzpicture}[remember picture, overlay] \draw[fill=LightSkyBlue] (0,0) rectangle (\paperwidth,3cm); \node[anchor=east,xshift=.9\paperwidth,rectangle, rounded corners=20pt,inner sep=11pt, fill=MidnightBlue] {\color{white}\chapterlabel#1}; \end{tikzpicture} }; \end{tikzpicture} } \titlespacing*{\chapter}{0pt}{50pt}{-60pt} \begin{document} \tableofcontents \chapter{Introduction} Text \chapter{Main} \section{Section} Text \begin{thebibliography}{99} \bibitem{Test} test reference \end{thebibliography} \end{document}
Screenshot:

See also pdf output of this test & demo file.
This entry was posted on 11 October 2008 at 10:31 PM and is filed under Sectioning, Graphics, Layout. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.




12 October 2008 at 8:07 AM
Nice example Stefan! I was thinking about creating something similar myself, but now I don’t have to
Can I add it to the TikZ examples gallery[1]?
[1] http://www.texample.net/tikz/examples/
12 October 2008 at 4:00 PM
Hi Kjell! Of course you’re allowed add it, I would see it with pleasure in your gallery.
Stefan
12 October 2008 at 9:03 PM
Thanks Stefan. The example is now online: http://www.texample.net/tikz/examples/fancy-chapter-headings/
Thank you for sharing.
- Kjell Magne
13 October 2008 at 12:06 PM
Hi Stefan,
I just tried the above example in a TeXLive installation (Ubuntu 8.04) and pdflatex gives me the following error:
! LaTeX Error: Unknown option `explicit’ for package `titlesec’.
However your example at LaTeX-Community.org works fine. I checked the ‘titlesec’ doc and it says there’s a package option called “explicit”.
I can’t seem to figure whats wrong. Can you reproduce the error?
-Gaveen
(SkyEye in LC)
13 October 2008 at 2:10 PM
Hi Gaveen,
Ubuntu 8.04 comes with titlesec v2.6. The “explicit” option was introduced in v2.7 2007-03-27.
If you want to use this option you would have to update titlesec. I’ve installed titlesec v2.8 using the MiKTeX package manager, but you could get it from CTAN too.
Stefan
13 October 2008 at 7:41 PM
Hi,
I posted a related example today that shows how to modify the current page node in cases where you want to print a page on stock paper that is larger than your page size:
http://www.texample.net/tikz/examples/modifying-current-page-node/
It is written with the Memoir document class in mind, but it should be straightforward to adapt it to other document classes.
- Kjell Magne
31 October 2008 at 10:40 PM
hey,
very nice example, i will keep this solution in mind.
-bob
(uni manchester)
25 November 2008 at 7:38 PM
Hi Stefan,
I like this solution very much! And I wonder whether it is difficult to extended it to title and parts (and probably subsections). Well, I think that I’m able to draw the same rectangle instead of title, but how to do this “uniformly”?
4 December 2008 at 5:01 PM
Hi Sasha,
thank you for your comment! I’m sorry that I didn’t respond quickly. I’m travelling since some weeks because of business.
I think it’s not hard to adapt this example for sections etc. For instance use \titleformat{subsection}{…} similar.
Stefan
3 January 2009 at 1:25 PM
Hi,
first I have to say that it is a nice use. I tried a similar thing using tikz and komascript for fancy page headings but the placement is certainly a problem because the placement of the actual heading is changing depending on the page spread and other factors. How would you do fancy page headings?
Andreas
4 January 2009 at 6:16 PM
Hi Andreas,
the solution above could be easily applied together with fancyhdr or scrpage2 to be used in general headings.
Here’s a modified compilable example using scrpage2 and scrartcl:
Output: fancy_headings.pdf.
Stefan