Typography with TeX and LaTeX

## Fancy chapter headings with TikZ

Oktober 11th, 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.

Later question on TeX.SX: Fancy chapter headings - perhaps you have an addition to that?

This entry was posted on Samstag, Oktober 11th, 2008 at 22:31 and is filed under pgf/TikZ, Sectioning, 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.

### 78 responses about “Fancy chapter headings with TikZ”

1. Kjell Magne Fauske said:

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]?

2. Stefan Kottwitz said:

Hi Kjell! Of course you’re allowed add it, I would see it with pleasure in your gallery.

Stefan

3. Kjell Magne Fauske said:

Thanks Stefan. The example is now online: http://www.texample.net/tikz/examples/fancy-chapter-headings/

Thank you for sharing.

- Kjell Magne

4. Gaveen said:

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)

5. Stefan Kottwitz said:

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

6. Kjell Magne Fauske said:

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

7. bobmalaria said:

hey,

very nice example, i will keep this solution in mind.

-bob
(uni manchester)

8. Sasha said:

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”?

9. Stefan Kottwitz said:

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

10. Andreas said:

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

11. Stefan Kottwitz said:

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:

\documentclass[svgnames]{scrartcl} \usepackage[automark]{scrpage2} \usepackage[english]{babel} \usepackage{blindtext} \usepackage{tikz} \newcommand*\tikzhead[1]{% \begin{tikzpicture}[remember picture,overlay] \node[yshift=-2cm] at (current page.north west) {\begin{tikzpicture}[remember picture, overlay] \draw[fill=LightSkyBlue] (0,0) rectangle (\paperwidth,2cm); \node[anchor=east,xshift=.9\paperwidth,rectangle, rounded corners=15pt,inner sep=11pt, fill=MidnightBlue] {\color{white}#1}; \end{tikzpicture} }; \end{tikzpicture}} \clearscrheadings \ihead{\tikzhead{\headmark}} \pagestyle{scrheadings} \begin{document} \tableofcontents \clearpage \blinddocument \end{document}

Stefan

12. Jesse said:

Hi Stefan,

You seem to be highly skilled at Latex chapter headings, so I wondered if you could help me with a problem I’m currently having? I’m essentially trying to include a small picture to the right of a left-justified chapter heading. For example, it would look something like this:

_____________
Chapter 1 | |
| Picture |
INTRODUCTION |_____________|

Any idea how to do that? Thanks!

Jesse

13. Jesse said:

Sorry, the format of my little example got a little screwed up when I submitted it. But hopefully you get the idea that the *picture* is supposed to be to the right of the “Chapter 1, Introduction” bit…

Thanks,

Jesse

14. Roberto said:

Hi Stefan,

thanks for you sharing on this magnificent and well designed chapter heading example. I’m wondering if you can help me to solve a problem: how to span long chapter names over a new (extra) line? I think we Brazilians (latinos) have some issue with trying to be minimalist

cheers,

Roberto

15. Stefan Kottwitz said:

Hi Jesse,

unfortunately I didn’t find time to write during the last days. Now here’s an example using titlesec. I’ve just used \includegraphics and \hfill to push the picture to the right:

\documentclass{report} \usepackage{titlesec} \titleformat{\chapter}[display] {\normalfont\huge\bfseries} {\chaptertitlename\ \thechapter\hfill \includegraphics[width=4em,height=2ex]{file}} {20pt}{\Huge} \usepackage[demo]{graphicx} \begin{document} \chapter{One} \chapter{Two} \end{document}

Stefan

16. Stefan Kottwitz said:

Hi Roberto,

in the example above you could use \parbox if your chapter title is taking more than one line:

\chapter[short title for the toc]{% \parbox[t]{\textwidth}{long title}}

Stefan

17. Roberto said:

Stefan,

many thanks for your prompt help — just in time to finish an ebook,

Roberto

18. Laki said:

Hi Stefan,

How can i adopt for book typing? I look forward from you.

19. Jason Lewis said:

Hi Stefan,

I’m looking at your solution to do fancy headers in comment #11.

I’d like to do something similar using the fancyhdr package but also, be able to change the header colour on a per chapter basis.

Any idea how I might achieve that?

thanks,

Jason

20. Stefan Kottwitz said:

Hi Jason,

here’s a solution using the article class and the fancyhdr package with the possibility to change the header color whenever you want:


Stefan

21. Aleksandra said:

Hi Stefan,

I have used your idea to get this beautiful headings in my book. So I have used solution with tikz and fancyhdr packages in book class, and tried to move chapter heading to the left on left hand side pages by using ifthen package, but as I am not very skilled user, all I got was a bunch of mistakes.

Do you have any suggestion how to solve this?

Thank you in advance,
Aleksandra

22. yell said:

Hi Stefan,

i want to use your awesome headings for my thesis. Unfortunately i just discovered, that my page numbering disappeared. is there a way to include them in the header or display them at the bottom of the page?

23. Stefan Kottwitz said:

Hi yell,

just use commands of the package (fancyhdr or scrpage2) that you are using, for instance

\cfoot{\thepage}

If you would need more help just provide more information, which class and which package(s) you are using, or a small compilable example like I’ve given above.

Stefan

24. yell said:

Unfortunately it doesnt work with that fix either.
I get pagenumbers at the bottom of the first content page, biblio page and on every page i just started a new chapter, but nowhere else.
Below is a small example i am using, which doesnt have a pagenumber on page 2.

\documentclass[svgnames, a4paper, twoside, titlepage, 11pt,pagenumber=botleft, BCOR12mm]{book}
\usepackage{tikz}
\usetikzlibrary{decorations}
\usetikzlibrary{decorations.pathmorphing}
\usetikzlibrary{decorations.markings}

\usepackage[automark]{scrpage2}
\usepackage[english]{babel}
\usepackage{blindtext}
\cfoot{\thepage}

\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{tikzpicture}[remember picture,overlay]
\node[yshift=-2cm] at (current page.north west)
{\begin{tikzpicture}[remember picture, overlay]
\draw[fill=LightSkyBlue] (0,0) rectangle
(\paperwidth,2cm);
\node[anchor=east,xshift=.9\paperwidth,rectangle,
rounded corners=15pt,inner sep=11pt,
fill=MidnightBlue]
{\color{white}#1};
\end{tikzpicture}
};
\end{tikzpicture}}

%\usepackage[top=3cm, inner=3cm,outer=3cm,bottom=3cm]{geometry}

\usepackage[thmmarks, amsthm]{ntheorem}
\usepackage{amsmath, amssymb}
\usepackage[english]{babel}
\usepackage[latin1]{inputenc}

\usepackage[draft]{fixme}%fixme-randbemerkungen
\setlength{\marginparwidth}{25mm} %breite fuer fixme
%\usepackage{xcolor}

\usepackage{xy}
%\usepackage{graphicx}
\usepackage{verbatim}
\usepackage{enumerate}
\usepackage{url}
\usepackage{sseq} %spectral sequence

\usepackage{makeidx}%index machen

\makeindex

\interfootnotelinepenalty=2000

\input xy
\xyoption{all}

\include{commands}
%\newcommand{\coloneqq}{:=}

%entrymodifiers lets xypic and limits work nicely together
\entrymodifiers={+!!}

\begin{document}
\tableofcontents

\newpage
test

\printindex
\bibliographystyle{amsalpha}
%\renewcommand{\bibname}{Literature}
\bibliography{asd}
\end{document}

25. Rafael R. Pappalardo said:

Could you try to put the \cfoot command just below the \begin{document} line?
It works for me.

Rafael

26. Stefan Kottwitz said:

Hi Rafael,

yell has already told me by email that his problem is solved, though he did not post the corrected code.
I think it’s just the \clearscrheadings in his code that cleared also the entry in the page footer. Your suggestion would fix that. It would be enough to place the \cfoot command right after \clearscrheadings or just not to use \clearscrheadings but \chead[]{} etc. instead.

Stefan

27. Campbel said:

Hi, I have a section heading that is spanning more than one line and when i used \parbox, it was out of the paper margin. I mean the total length is more than what it should be. How can i handle this and i dont want to use - when breaking the last word. I want the last word to go to another line and at the same time not to maintain a double space between the section name.

28. Stefan Kottwitz said:

Hi Campbel!

You could just use \\ or \newline to break the line inside the \parbox. Perhaps show a minimal example that shows the problem in detail, the code example would allow to give really appropriate help.

Stefan

29. Jennifer said:

Hi Stefan,

I am currently writing on my Uni thesis and because I really enjoy good looking layouts and liked your idea, I was wondering if you could answer me two questions (Please not that I am fairly new to Latex):

1. Is it possible to split the chapter number and chapter name into 2 different boxes?

2. Can I fill the big lightskyblue box with external pictures (i.e. jpgs or similar)?

Thank you
Jennifer

30. vahid damanafshan said:

Dear Stefan,
Thank you for this example. Can I add the above example to my blog?

31. Stefan Kottwitz said:

Hi Vahid,

of course you can add it, feel free to use the code. Perhaps provide a link back to this page allowing the visitors of your blog to read the discussion and examples here as well.

Best regards,

Stefan

32. Vahid Damanafshan said:

Hi Stefan,
Thank you so much. The example is online at:

33. - said:

Hi Stefan,

I’m a LaTeX noobie just started working with it.
I want to have a chapter title without the chapter part and a big number instead of a small. I found out how to do the first part, but i cant get a bigger number.

i want this for example:

“a big number” 2.
title name: Introduction

tnx.

34. Stefan Kottwitz said:

Hi,

that’s no problem if you would use the titlesec package, try this example:

\documentclass[a4paper,10pt]{book} \usepackage[english]{babel} \usepackage{blindtext} \usepackage{lmodern} \usepackage{fixltx2e} \usepackage{titlesec} \titleformat{\chapter}[display] {\fontsize{80pt}{90pt}\selectfont\bfseries} {\thechapter}{20pt}{\Huge} \begin{document} \Blinddocument \end{document}

titlesec provides many features to customize chapter headings. The fncychap package offers more chapter heading styles.

Stefan

35. Kevin said:

Wow! this is great code and helpful comments! I’m a very bad LaTeX noob and this is very insightful. One question: Is there any way to make this bar appear at the bottom of the page (with the page number embedded into it) instead of the top?

36. Stefan Kottwitz said:

Hi Kevin!

Thank you for your comment. We all were LaTeX beginners at some time. Concerning your question, you could use foot commands of fancyhdr or scrpage, further change the relation to the current page node, like south west instead of north west. Here’s the comment #11 modified with this intention:

\documentclass[svgnames]{scrartcl} \usepackage[automark]{scrpage2} \usepackage[english]{babel} \usepackage{blindtext} \usepackage{tikz} \newcommand*\tikzhead[1]{% \begin{tikzpicture}[remember picture,overlay] \node at (current page.south west) {\begin{tikzpicture}[remember picture, overlay] \draw[fill=LightSkyBlue] (0,0) rectangle (\paperwidth,2cm); \node[anchor=east,xshift=.9\paperwidth, yshift=2cm,rectangle, rounded corners=15pt,inner sep=11pt, fill=MidnightBlue] {\color{white}#1}; \end{tikzpicture} }; \end{tikzpicture}} \clearscrheadings \ifoot{\tikzhead{Page \thepage}} \pagestyle{scrheadings} \begin{document} \tableofcontents \clearpage \blinddocument \end{document}

Stefan

37. Serban said:

Hi Stefan.

I have a problem with a custom header created with titlesec: it does not apply to the table of contents, list of figures and list of tables.
I tried your examples posted here and even though it should work, as I saw in the screenshot, it still doesn’t. I hoped you might have an idea about why this is happening. Maybe you can point me to a package that could solve this issue.

Thank you.
Serban

38. Stefan Kottwitz said:

Hi Serban,

could you create a compilable example that shows the problem and post it here? Without it I cannot see what your code actually does. If I could look at your titlesec related code, the best would be a small example, I could make a suggestion to fix it.
I think there’s no need for an additional package, but the \titleformat calls or something else would have to be changed.

Stefan

39. yanlong said:

Great post!
I have tried your code and it works out exactly as it is designed. However, it seems my hyperref anchors are now a little off the desired position. When I click a page number that points to a chapter, it only shows from beneath the chapter title. I guess it might have something to do with hyperref, which sometimes links to floats points below the caption and not at the beginning of the float. The caption package might be able to correct this, but I don’t know how, since I cannot find a place to command \capstart.

Any suggestions?
Thanks!

40. Stefan Kottwitz said:

Hi yanlong!

The anchor of the concerned hyperlink points to the beginning of the chapter, not at the heading created here. Perhaps in that case here the links should be adjusted to refer to the beginning of the page instead.
A redefinition of a hyperref macro could fix it perhaps, but this would need some time to investigate as the hyperref code is complex.
But it isn’t related to the caption package, this package has nothing to do with section or chapter headings.

Stefan

41. yanlong said:

Hi, Stefan,
Many thanks for your prompt response! I believe you are right that it is the way hyperref sets anchors for chapter titles. Even without your chapter labels, hyperref does not anchor at the top of the page. when I try the geometry package, I find that hyperref anchors at \geometry{top=xx}. If I reset \titlespacing* accordingly, I can only make the chapter title page look nice, but the rest pages would need further adjustment.

By my random and impatient guessing, you can tell that I am just a beginner, as I have only weeks of experience of using LaTeX, and I have tons of works due … The reason that I want to give up MS Office as a whole is TikZ and R …

I am glad that I found your blog and I will keep following your posts. Thanks!

yanlong

42. Serban said:

Hi again.

Thank you for the fast response.

Here is a running example with my titleformat for chapters and all the packages that I am using. As I said before, the contents heading does not change the style. If for you it works, maybe you can have an idea about what is different.

Thanks again,
Serban.

\documentclass[pdftex,a4paper,12pt]{report}
\usepackage[pdftex]{graphicx}
\usepackage[a4paper]{geometry}
\usepackage[x11names]{xcolor}
\usepackage{colortbl, tabularx, fancyhdr, lscape, layout}
\usepackage{tocloft, titlesec, appendix, caption, pifont}

\titleformat{\chapter}[block]
{\LARGE\bfseries\color{blue}\titlerule\setlength{\parskip}{0pt}}
{\colorbox{blue}{\parbox[c][50pt][c]{60pt}{
\hfil\color{white}\centering\normalsize\textit{Chapter}\\\Huge\thechapter\hfil}}}
{0pt}
{\hspace{30pt}\MakeUppercase}
[\titlerule]

\begin{document}
\tableofcontents
\newpage
\chapter{Aaaa}
\chapter{Bbbb}
\chapter{Cccc}
\end{document}

43. Serban said:

Sorry to be posting again like this, but through an interesting trial an error approach and a bit if luck I found out where the problem is: the tocloft package. If you remove that from the packages declaration it will work just fine. So it comes down to a question related to the tocloft package instead.

I know that this is not the topic of this post but if you have any solution on how I can make the two packages cooperate, I will be most grateful. I have posted the code that I am using from the tocloft package: some snippet to add the words chapter and appendix in front of the respective chapter numbers/letters in the table of contents. I apologize for the ugly code but I have no idea how to put it in the code box.

Thank you.
Serban

\documentclass[pdftex,a4paper,12pt]{report}

\usepackage[x11names]{xcolor}
\usepackage{titlesec, tocloft}

\titleformat{\chapter}[block]
{\LARGE\bfseries\color{blue}\titlerule\setlength{\parskip}{0pt}}
{\colorbox{blue}{\parbox[c][50pt][c]{60pt}{
\hfil\color{white}\centering\normalsize\textit{Chapter}\\\Huge\thechapter\hfil}}}
{0pt}
{\hspace{30pt}\MakeUppercase}
[\titlerule]

\newlength{\tocnumwidth}
\newlength{\temp}
\setlength{\tocnumwidth}{\cftchapnumwidth}
\renewcommand{\cftchappresnum}{\color{blue}\chaptername\space\color{red}}
\renewcommand{\cftchapaftersnum}{.}
\settowidth{\temp}{\bfseries\cftchappresnum\cftchapaftersnum}
\DeclareRobustCommand{\changetoapp}{
\renewcommand*{\cftchappresnum}{\color{blue}\appendixname\space\color{red}}
\settowidth{\temp}{\bfseries\cftchappresnum\cftchapaftersnum}
\setlength\cftchapnumwidth{\tocnumwidth}
\let\oldappendix\appendix

\begin{document}
\tableofcontents
\chapter{Aaaa}
\chapter{Bbbb}
\chapter{Cccc}
\appendix
\chapter{Xxxx}
\chapter{Yyyy}
\chapter{Zzzz}
\end{document}

44. Stefan Kottwitz said:

Hi Serban,

here’s a quick workaround:

\makeatletter \renewcommand*{\@cftmaketoctitle}{% \chapter*{\contentsname}} \makeatother

Add this after loading tocloft, it will cause the tocloft toc heading to look like the normal \chapter* heading.
Note, with \chapter* there won’t be a number of course.

Stefan

45. Serban said:

Perfect. Thank you so much for your help.

Keep up the excellent work.

All the best,

Serban

46. Jan Fisker said:

I have read this nice forum, and as others at this forum, I im a noob at latex and tikzpictures, but I would like to know how to make both the header and the pagenumber at the same time, then i have a theme four my schoolproject.

47. Stefan Kottwitz said:

Hi Jan,

that’s no problem, just put \thepage somewhere. For instance like here as additional node:

\newcommand*\tikzhead[1]{% \begin{tikzpicture}[remember picture,overlay] \node[yshift=-2cm] at (current page.north west) {\begin{tikzpicture}[remember picture, overlay] \draw[fill=LightSkyBlue] (0,0) rectangle (\paperwidth,2cm); \node[anchor=east,xshift=.9\paperwidth,rectangle, rounded corners=15pt,inner sep=11pt, fill=MidnightBlue] {\color{white}#1}; \node[anchor=west,xshift=1cm,yshift=1cm] {\color{white}\Large\bfseries\thepage}; \end{tikzpicture} }; \end{tikzpicture}}

 \node[anchor=west,xshift=1cm,yshift=1cm] {\color{white}\Large\bfseries\thepage};

Stefan

48. Jan Fisker said:

Thx Stefan

looking at your suggestion i found out what i really wanted, se the “theme” as i took the header and footer and put them together in the same document.

\documentclass[svgnames]{scrartcl} \usepackage[automark]{scrpage2} \usepackage[english]{babel} \usepackage{blindtext} \usepackage{tikz} \newcommand*\tikzhead[1]{% \begin{tikzpicture}[remember picture,overlay] \node[yshift=-2cm] at (current page.north west) {\begin{tikzpicture}[remember picture, overlay] \draw[fill=LightSkyBlue] (0,0) rectangle (\paperwidth,2cm); \node[anchor=east,xshift=.9\paperwidth,rectangle, rounded corners=15pt,inner sep=11pt, fill=MidnightBlue] {\color{white}#1}; \end{tikzpicture} }; \end{tikzpicture}}

 \newcommand*\tikzfoot[1]{% \begin{tikzpicture}[remember picture,overlay] \node at (current page.south west) {\begin{tikzpicture}[remember picture, overlay] \draw[fill=LightSkyBlue] (0,0) rectangle (\paperwidth,2cm); \node[anchor=east,xshift=.9\paperwidth, yshift=2cm,rectangle, rounded corners=15pt,inner sep=11pt, fill=MidnightBlue] {\color{white}#1}; \end{tikzpicture} }; \end{tikzpicture}} 

\clearscrheadings \ifoot{\tikzfoot{Page \thepage}} \ihead{\tikzhead{\headmark}} \pagestyle{scrheadings} \begin{document} \tableofcontents \clearpage \blinddocument \end{document} 

49. Paul said:

Dear Stefan

this is very very nice work! How would you, for a book-class document with a single main titlepage, create a oval coloured box containing and putting the title on the main front page?

Thanks a lot

Paul

50. Arun K Ghosh said:

\usepackage[math]{easyeqn}
generates error messages with your beautiful heading generation program. Please let me know how I overcome this problem.

51. Arun K Ghosh said:

\usepackage[math]{easyeqn}
generates error messages with your beautiful heading generation program. Please let me know how I can overcome this problem.

52. jacqueline said:

I want to create a text with a banner with tikz. I want also be able to write and put graphics inside the banner like http://imagebin.ca/view/xI1TRFa.html. Please help in designing this page layout.
Many thanks

53. Stefan Kottwitz said:

Hi Jacqueline,

have a look at the TikZ example gallery to find good source code to start with.

Stefan

54. jacqueline said:

Yes, the one that I can start with is right on this page but I could not adapt it to my new situation. I also try to find another example in the library but most of them are graphics. Need help. Thanks

55. Christoph Päper said:

Is there an elegant solution to make this compatible with “twoside”?
I can make two very similar tikzpicture and use them in \lefoot and \rofoot respectively, but I’d rather just change “\node[anchor=east, xshift=0.9\paperwidth]”.

56. Stefan Kottwitz said:

Hi Christoph!

Sorry, I didn’t have time to write on the blog, due to the daily work.
You could solve it using commands like
\ifthispageodd{true}{false} 
or
\checkoddpage 
of the changepage package, see: Finding if you’re on an odd or an even page in the UK TeX FAQ.

Stefan

57. PS said:

The latex compiler says:
(/usr/share/texmf/tex/latex/xcolor/svgnam.def
! Undefined control sequence.
l.32 \preparecolorset
{rgb}{}{}{%
if i use:
\documentclass[svgnames]{scrreprt}
\usepackage{tikz}

If i drop \usepackage{tikz} and any tikz-relevant stuff, it will compile. But if i use those commands together, it won’t work out for me?

58. Mat said:

Hello!

A beautiful example! I have successfully employed the code to create a very nice looking chapter-header. However I’m facing at the moment the problem that I would like to share this chapter-header with people that use dvi+ps+gs to compile their .tex-files. It so happens that the outcome is not the same
With pdftex your example looks perfectly fine, when compiling with TeX+dvi it has a white space above the bright-blue-background-bar.
I think the bug comes from the node&remember picture commands…but I must admit that after trying out several things that might resolve it, I still couldn’t really find a solution… I’m not a tikx-expert unfortunately :-/

Any thoughts how to make this work with dvi+ps+gs?

With best regards!

Mat

59. Mat said:

Hello again,

I have just found the error linked to the example here:
It seems that on my configuration the dvi package uses a different default page-size than the pdftex -> when specifying in the first line of your example:
\documentclass[a4paper,svgnames]{report}
there is no difference any more between the compilation with TeX+dvi instead of pdftex. Strange…since if things would work as they should, tikz should not have a different reference point for the current page anchors if there is no paper-size definition… but well: it works without problems when a4 (or a different paper format) is explicitly specified.
(Btw: I’m working with the Mac TeX Live 2010 distribution)

However this does not resolve yet the problem with my own example
Here is a minimal working example:


The compilation with pdftex works fine -> the output is a kind of thumbindex-like chapter-header style where the chapter-number appears in the black box.
However when compiling with TeX+dvi the chapter-names disappear behind the black box.
An additionally strange thing is: it needs to be compiled 3 times in order to appear correctly. at the second time the chapter headers are still at the bottom of the page… I was not that worried since at the third compilation it works without trouble, but its an additional thing that I didn’t understand and might be linked to the problem?

Any help would be highly appreciated!

Mat

60. Stefan Kottwitz said:

Hi Mat,

which is your final output format? If it’s DVI or PS, pdfTeX is not an option. However, if you finally produce PDF, I would use pdfTeX. It offers some advantages: besides better PDF support it works with PNG and JPEG, further it provides microtypographic features. If you depend on DVI/TeX because of EPS support, this can be resolved by using the epstopdf package.

Stefan

61. Mat said:

Hello Stefan,

Thanks for your reply. Personally I prefer pdfTeX as well. The output is much neater than when produced with dvi/PS. I would be very happy to leave it there. My chapter header proposition is however for a template for a larger community (my university) and it seems that some would really much prefer the dvi/PS option :-/

I expect there is probably just some little bug in my code which prevents the correct output for the TeX+DVI compilation.
But I also don’t want to bother you for too long with this unless you directly “see” where my bug is coming from

Mat

62. paul said:

hi stefan,

very nice blog

i am using pdflatex package to write my phd thesis. some of my chapter headings has greek letters in it but when i run pdflatex it shows error. if i remove the greek letter it runs smoothly while except the heading in other portion of the text greek letters are not creating any problem. what can be the problem.

63. Stefan Kottwitz said:

Hi Paul,

you could show the error message or a code sample which produces that error. Greek letters in headings could cause problems in PDF bookmarks.

Stefan

64. Remi said:

Hi Stefan, I’m having a little problem with your original example of fancy chapter headings; I just copied/pasted the code in Texmaker (I’m a windows user) and I have some errors such as:
“Paragraph ended before \ttl@format@ii was complete (line 12)”

“You can’t use’ macro parameter character #’ in restricted horizontal mode (line 21)”

” missing \begin{document} (line 25)”…

I’m a little bit of a latex noob, so please excuse me if they are trivial errors…

Thank you !

Remi

PS: I produce my file with pdflatex… maybe it has something to see…

65. Stefan Kottwitz said:

Hi Remi,

I guess there’s in error in your \titleformat line (because of the \ttl@format@ii error), such as a missing argument, you could show that line here.

Stefan

66. Remi said:

Hi Stefan,
thank you for the quick answer !

the line :

\titleformat{\chapter}
{\gdef\chapterlabel{}
\normalfont\sffamily\Huge\bfseries\scshape}
{\gdef\chapterlabel{\thechapter\ }}{0pt}

Thanks.

Remi

67. Francois said:

Hi Stefan!

That’s really nice! Im really a newbie so excuse me in advance for my probably stupid question

Im writing a report (class article) and I wanted put my section headers in boxes. I really like your example so I tried to modify it just to keep the blue box for my section titles. But I have some problems: the box always stay in the top of the page and not in the place of the section, and anyway I cannot take just the box, without your lighter background..

I would greatly appreciate your help!

Francois

68. Francois said:

It is alright I found what I wanted!

Thanks for your nice blog!

69. Stefan Kottwitz said:

Hi Francois, nice to hear that you found it!

70. Kyle said:

Hi Stefan -

This is incredible. Thanks very much for putting all this up. I’ve been looking for a way to insert a colored header for weeks. I tried making an eps file, drawing pictures, lines and inputting it as a picture, etc. and nothing worked!

I’m working with the example you posted on April 1 2009 so that I can control the headings on each page:


My goal is to combine the above code with something to also add a footer as well- so that I have a colored footer and header for each page. I have tried by looking at your reply to Kevin on March 11th but have been unsuccessful.

Do you have any suggestions for including a colored header and footer on each page? Would greatly appreciate any help.

Kyle

71. Jyo said:

Just came across this today — it’s much nicer than what I was looking for. Thanks for sharing the code.

72. Verena said:

Hello Stefan!

Have you by any chance ever tried (and managed to) get the lovely style you defined for your chapters/sections/… work for the bibliographic part of the same document as well?
Cause that’s the issue I’m currently working on. I’ve got all those nice and fancy headings thoughout my work, and for the “References” header, Latex swaps back to the predefined style. Which is a pity.

If you happen to have an idea on how to solve this, I’d be much obliged.

Greetings.

73. Saki said:

I have a problem when using the above code along with
\bibliographystyle{spmpsci}
\bibliography{../references}

Anybody have any idea why?

I get the error message:
! LaTeX Error: Something’s wrong–perhaps a missing \item.

See the LaTeX manual or LaTeX Companion for explanation.
Type H for immediate help.

l.1 \begin{thebibliography}{100}

I did notice that I have more that 100 references but this file is automatically created.

Thank you for any info.

74. tom said:

Hi Stefan,

I am writing a post on chapter styles and would like to mention your example above. I’ll add a link to this site. Would that be ok with you?

Thanks and regards, Tom.

75. Stefan Kottwitz said:

Hi Tom,

of course that’s ok! The information here is for using and sharing, and linking back to the original is very good.

Stefan

76. Wendell said:

Hi, Stefan!

Great work and thank you, im using it on my works and everybody liked it!

I am a beginner in Latex and Tikz and I was thinking, is it possible to make a fancy cover for a report that follows the style of the chapter headers, perhaps modifying \maketitle macro?

Thank you!

77. Lena said:

Thank you!!!

78. BM said:

Hi!
This is a great, I was wondering how to keep the chapter heading on every page, not only only on the first page?