# How to change the chapter header font/layout?

I'm trying to make a chapter header style to mimic the image as follows:

I've got the following code currently, but not sure how to get the line in the middle, and the title of the chapter to be below the chapter number.

\documentclass{book}
\usepackage{titlesec, blindtext, color}

\usepackage{titlesec}
\titleformat{\chapter}{\Huge}{\Large CHAPTER \Huge\thechapter\newline}{0pt}{\Huge}

\begin{document}
\chapter{Turing Machines}
\end{document}


Also related to this task: I'd like to know if there's any way to selectively customize the font of a section header without having to change the default font of the whole document. I'm using pdflatex on Windows via MiKTeX, and one package I tried - I forget the name of it now, but I think it might have been fontspec - wouldn't work with pdflatex.

-
fontspec only works with XeTeX and LuaTeX. – Sašo Živanović Jan 29 '13 at 22:18

I have a little code that I took from a German website some times ago (I can not find it to reference sadly). With a little modification it is partially similar to what you are looking for. Maybe it can be a good starting point:

\documentclass{scrbook}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{xcolor}
\colorlet{chapter}{cyan}

\makeatletter
\renewcommand*{\chapterformat}{
\begingroup
\setlength{\unitlength}{1mm}
\begin{picture}(40,30)(0,5)
\setlength{\fboxsep}{0pt}
\put(0,15){\line(1,0){\dimexpr
\textwidth-1\unitlength\relax\@gobble}}
\put(40,15){\makebox(\dimexpr
\textwidth-20\unitlength\relax\@gobble,\ht\strutbox\@gobble)[l]{
\ \normalsize\color{cyan}\chapapp~\thechapter\autodot
}}
\end{picture}
\endgroup
}
\makeatother

\begin{document}
\chapter{Alan Turing}
\end{document}


-
It does indeed look similar, but one big difference is the fact that the line doesn't extend to the edge of the page; it only reaches the margins. I'll see if I can get it working though, since it is pretty close. – agent154 Jan 30 '13 at 1:27
@agent154, You are right! I didn't pay attention to the line. But again, I thought it's close enough and can be a starting point. cheers. – Pouya Jan 30 '13 at 8:54

I ended up doing this through usage of tikz.

Ignore the text - that's a work in progress, as well as the formatting for it all. But I got the chapter header just how I wanted it, which after playing around turned out to be a bit different than the image above.

\usepackage{kpfonts}
\usepackage[explicit]{titlesec}
\usepackage{tikz}

\titleformat{\chapter}
{\normalfont\sffamily\Huge\scshape}
{}{0pt}
{\begin{tikzpicture}[remember picture,overlay]
\node[yshift=-3cm] at (current page.north west)
{\begin{tikzpicture}[remember picture, overlay]
\draw[fill=cyan] (0,-1) rectangle
(\paperwidth,3cm);
\node[anchor=west,xshift=.21\paperwidth,yshift=-.01\paperheight,rectangle]
{\color{white}\LARGE CHAPTER \Huge\thechapter};
\node[anchor=west,xshift=.21\paperwidth,yshift=-.065\paperheight,rectangle]
{\color{cyan}\Huge\MakeUppercase{#1}};
\end{tikzpicture}
};
\end{tikzpicture}
}
\titlespacing*{\chapter}{0pt}{50pt}{0pt}

\begin{document}
\chapter{Test}
\end{chapter}


I'm using a custom made class file, so I only included what I think is the bare minimum to get the heading to show... it won't ultimately look exactly like in this image with the spacing and other text positioning.

-

\documentclass{report}

\usepackage{kpfonts}
\usepackage[explicit]{titlesec}
\usepackage{tikz}

\makeatletter
\newcommand{\gettikzxy}[3]{%
\tikz@scan@one@point\pgfutil@firstofone#1\relax
\edef#2{\the\pgf@x}%
\edef#3{\the\pgf@y}%
}
\makeatother

\titleformat{\chapter}
{\normalfont\sffamily\Huge\scshape}
{}{0pt}
{\begin{tikzpicture}[remember picture,overlay]
\node[yshift=-3cm] at (current page.north west)
{\begin{tikzpicture}[remember picture, overlay]
\node(chapter)[anchor=west,xshift=.21\paperwidth,yshift=-.01\paperheight,rectangle]
{\color{cyan}\normalsize CHAPTER \Huge\thechapter};
\gettikzxy{(chapter)}{\chapterx}{\chaptery}
\draw[color=cyan] (0,\chaptery-25) -- ++ (\paperwidth,0);
\node[anchor=west,xshift=.21\paperwidth,yshift=-.065\paperheight,rectangle]
{\color{cyan}\Huge\bfseries\MakeUppercase{#1}};
\end{tikzpicture}
};
\end{tikzpicture}
}
\titlespacing*{\chapter}{0pt}{50pt}{0pt}

\begin{document}
\chapter{Speaking mathematically}
\end{document}

-