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.




Oktober 12th, 2008 at 08:07
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/
Oktober 12th, 2008 at 16:00
Hi Kjell! Of course you’re allowed add it, I would see it with pleasure in your gallery.
Stefan
Oktober 12th, 2008 at 21:03
Thanks Stefan. The example is now online: http://www.texample.net/tikz/examples/fancy-chapter-headings/
Thank you for sharing.
- Kjell Magne
Oktober 13th, 2008 at 12:06
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)
Oktober 13th, 2008 at 14:10
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
Oktober 13th, 2008 at 19:41
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
Oktober 31st, 2008 at 22:40
hey,
very nice example, i will keep this solution in mind.
-bob
(uni manchester)
November 25th, 2008 at 19:38
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”?
Dezember 4th, 2008 at 17:01
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
Januar 3rd, 2009 at 13:25
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
Januar 4th, 2009 at 18:16
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
Januar 25th, 2009 at 07:55
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
Januar 25th, 2009 at 07:58
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
Februar 4th, 2009 at 20:06
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
Februar 8th, 2009 at 10:56
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:
Stefan
Februar 8th, 2009 at 11:03
Hi Roberto,
in the example above you could use \parbox if your chapter title is taking more than one line:
Stefan
Februar 9th, 2009 at 14:53
Stefan,
many thanks for your prompt help — just in time to finish an ebook,
Roberto
März 7th, 2009 at 09:22
Hi Stefan,
How can i adopt for book typing? I look forward from you.
April 1st, 2009 at 05:27
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
April 1st, 2009 at 18:35
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
Juli 19th, 2009 at 09:56
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
August 22nd, 2009 at 19:20
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?
August 22nd, 2009 at 23:07
Hi yell,
just use commands of the package (fancyhdr or scrpage2) that you are using, for instance
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
August 23rd, 2009 at 01:10
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}
\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}
%\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
\usepackage{hyperref}%klickbare links
\makeindex
\interfootnotelinepenalty=2000
\input xy
\xyoption{all}
\include{commands}
%\newcommand{\coloneqq}{:=}
\linespread {1.1}
%entrymodifiers lets xypic and limits work nicely together
\entrymodifiers={+!!}
\begin{document}
\tableofcontents
\newpage
test
\printindex
\bibliographystyle{amsalpha}
%\renewcommand{\bibname}{Literature}
\addcontentsline{toc}{chapter}{\bibname}
\bibliography{asd}
\end{document}
September 15th, 2009 at 17:40
Could you try to put the \cfoot command just below the \begin{document} line?
It works for me.
Rafael
September 15th, 2009 at 18:43
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
Dezember 1st, 2009 at 11:59
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.
Dezember 7th, 2009 at 22:12
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
Januar 15th, 2010 at 22:41
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
Februar 10th, 2010 at 22:57
Dear Stefan,
Thank you for this example. Can I add the above example to my blog?
Februar 11th, 2010 at 00:57
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
Februar 12th, 2010 at 21:20
Hi Stefan,
Thank you so much. The example is online at:
http://vdamanafshan.blogspot.com/2010/02/fancy-chapter-headings-with-tikz.html
März 5th, 2010 at 17:56
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.
März 8th, 2010 at 22:17
Hi,
that’s no problem if you would use the titlesec package, try this example:
titlesec provides many features to customize chapter headings. The fncychap package offers more chapter heading styles.
Stefan
März 9th, 2010 at 19:37
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?
März 11th, 2010 at 20:18
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:
Stefan
Mai 21st, 2010 at 05:08
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
Mai 21st, 2010 at 06:52
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
Mai 21st, 2010 at 06:56
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!
Mai 21st, 2010 at 10:54
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
Mai 22nd, 2010 at 04:36
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
Mai 23rd, 2010 at 05:38
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}
Mai 23rd, 2010 at 06:27
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}
\addtolength{\cftchapnumwidth}{\temp}
\DeclareRobustCommand{\changetoapp}{
\renewcommand*{\cftchappresnum}{\color{blue}\appendixname\space\color{red}}
\settowidth{\temp}{\bfseries\cftchappresnum\cftchapaftersnum}
\setlength\cftchapnumwidth{\tocnumwidth}
\addtolength{\cftchapnumwidth}{\temp}}
\let\oldappendix\appendix
\renewcommand*{\appendix}{\oldappendix \addtocontents{toc}{\changetoapp}}
\begin{document}
\tableofcontents
\chapter{Aaaa}
\chapter{Bbbb}
\chapter{Cccc}
\appendix
\chapter{Xxxx}
\chapter{Yyyy}
\chapter{Zzzz}
\end{document}
Mai 23rd, 2010 at 21:49
Hi Serban,
here’s a quick workaround:
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
Mai 24th, 2010 at 11:38
Perfect. Thank you so much for your help.
Keep up the excellent work.
All the best,
Serban
Juni 8th, 2010 at 23:48
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.
Juni 9th, 2010 at 21:32
Hi Jan,
that’s no problem, just put \thepage somewhere. For instance like here as additional node:
The addition was
Stefan
Juni 9th, 2010 at 23:16
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}
Juni 30th, 2010 at 12:22
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
September 11th, 2010 at 12:27
\usepackage[math]{easyeqn}
generates error messages with your beautiful heading generation program. Please let me know how I overcome this problem.
September 11th, 2010 at 12:29
\usepackage[math]{easyeqn}
generates error messages with your beautiful heading generation program. Please let me know how I can overcome this problem.
September 14th, 2010 at 02:11
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
September 14th, 2010 at 14:44
Hi Jacqueline,
have a look at the TikZ example gallery to find good source code to start with.
Stefan
September 14th, 2010 at 15:36
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
September 18th, 2010 at 19:26
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]”.
September 30th, 2010 at 22:48
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
Oktober 17th, 2010 at 13:06
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?
Juni 24th, 2011 at 01:04
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
Juni 25th, 2011 at 13:39
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
Juni 25th, 2011 at 14:51
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
Juni 25th, 2011 at 16:12
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
September 6th, 2011 at 08:41
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.
September 10th, 2011 at 14:46
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
September 10th, 2011 at 15:18
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…
September 11th, 2011 at 14:55
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
September 20th, 2011 at 20:38
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
Oktober 21st, 2011 at 13:54
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
Oktober 23rd, 2011 at 18:51
It is alright I found what I wanted!
Thanks for your nice blog!
Oktober 25th, 2011 at 12:12
Hi Francois, nice to hear that you found it!
November 25th, 2011 at 02:48
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:
\documentclass[svgnames]{article}
\usepackage{fancyhdr}
\usepackage[english]{babel}
\usepackage{blindtext}
\usepackage{tikz}
\newcommand*\tikzhead{%
\begin{tikzpicture}[remember picture,overlay]
\node[yshift=-2cm] at (current page.north west)
{\begin{tikzpicture}[remember picture, overlay]
\draw[fill=\headcolor] (0,0) rectangle
(\paperwidth,2cm);
\end{tikzpicture}
};
\end{tikzpicture}}
\fancyhf{}
\renewcommand*\headrulewidth{0pt}
\chead{\tikzhead}
\pagestyle{fancy}
\newcommand*\headcolor{Aqua}
\newcommand*\setheadcolor[1]{\renewcommand*\headcolor{#1}}
\begin{document}
\setheadcolor{Gold}
\tableofcontents
\clearpage
\setheadcolor{Olive}
\blinddocument
\end{document}
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
Dezember 4th, 2011 at 06:26
Just came across this today — it’s much nicer than what I was looking for. Thanks for sharing the code.
Januar 18th, 2012 at 14:12
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.
Mai 12th, 2012 at 22:33
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.