I am trying to use fancyhdr to create headers with color backgrounds.
I'd also like the page numbers to be larger and the section names to
be smaller. Here is the idea in Ugly Ascii Art:
+-------------------------------------------------------+
| ## |
| This is the name of the chapter ## |
+-------------------------------------------------------+
(this should extends over the text width)
##
## is the number of the page in \Large. Sides for page number/chapter
name should be reversed for even/odd pages.
First I've set fancyhead to:
\fancyhead[LE,RO]{\colorbox{darkgray}{\textcolor{white}{\bfseries\Large\thepage}}}
\fancyhead[LO,RE]{\colorbox{darkgray}{\textcolor{white}{\bfseries\small\leftmark}}}
This seems to work, but 1) the color box does not extends over all the
text area as I wished, and 2) I am quite sure the height of the color
box is different when covering, say, pages IV and V.
I've also tried to fiddle with colortbl, but no success. I had some
results with \makebox but they were ugly and the boxes for the chapter
name and page number were sort of displaced - the chapter title was a
little more to the top of the page. In other words, it did not work.
Does anyone have any suggestion/package/real cool code? Thanks in
advance
Rafael
(p.s. I am unable to post thanks and solutions to the mailing list via
google/groups on the same thread, will do that on new threads)
>I am trying to use fancyhdr to create headers with color backgrounds.
>I'd also like the page numbers to be larger and the section names to
>be smaller. Here is the idea in Ugly Ascii Art:
>
>
>+-------------------------------------------------------+
>| ## |
>| This is the name of the chapter ## |
>+-------------------------------------------------------+
> (this should extends over the text width)
>
>##
>## is the number of the page in \Large. Sides for page number/chapter
>name should be reversed for even/odd pages.
>
>First I've set fancyhead to:
>
>\fancyhead[LE,RO]{\colorbox{darkgray}{\textcolor{white}{\bfseries\Large\thepage}}}
>\fancyhead[LO,RE]{\colorbox{darkgray}{\textcolor{white}{\bfseries\small\leftmark}}}
>
>This seems to work, but 1) the color box does not extends over all the
>text area as I wished, and 2) I am quite sure the height of the color
>box is different when covering, say, pages IV and V.
>
>I've also tried to fiddle with colortbl, but no success. I had some
>results with \makebox but they were ugly and the boxes for the chapter
>name and page number were sort of displaced - the chapter title was a
>little more to the top of the page. In other words, it did not work.
>
>Does anyone have any suggestion/package/real cool code? Thanks in
>advance
The variable height you could cure by adding a \strut which has a
constant height and depth usually at least as large as the tallest
glyph. A \vphantom{IVg} works also. The \colorbox you can make extending
by putting a wide \makebox[\textwidth] into it. Then set the border to
zero width by \fboxsep=0. Now you are on your own with the contents,
e. g. do your private strut by \vrule width 0pt. Example:
\documentclass[twoside]{article}
\usepackage{graphicx}
\usepackage{xcolor}
\usepackage{fancyhdr}
\lhead{}\chead{}\rhead{}
\fancyhead[LE]{\fboxsep=0pt%
\colorbox{darkgray}{\textcolor{white}{\makebox[\textwidth]{%
\normalsize\quad
\bfseries\small\leftmark\hfill
\Large\vrule height 2.5ex depth 1ex width 0pt\thepage
\normalsize\quad}}}}
\fancyhead[RO]{\fboxsep=0pt%
\colorbox{darkgray}{\textcolor{white}{\makebox[\textwidth]{%
\normalsize\quad
\bfseries\Large\vrule height 2.5ex depth 1ex width 0pt\thepage
\hfill\small\leftmark
\normalsize\quad}}}}
\chead{}
\pagestyle{fancy}
\begin{document}
\section{Intro} \input tufte\clearpage
\section{Next} \input tufte\clearpage
\end{document}
And maybe switch the headrulewidth off (forgot how this goes).
Regards, Hartmut
--
H. Henkel, Oftersheim
Well, actually \vphantom{IVg} may be inconsistent if one uses accented
characters, among other things. The following examples generates (at
11pt font size):
\setbox0=\hbox{IVg}\the\ht0 -> 7.54149pt
\setbox0=\hbox{\'I}\the\ht0 -> 9.39049pt
\setbox0=\hbox{\strut}\the\ht0 -> 9.51996pt
which indicates that the \vphantom suggestion is "shorter" than an
accented I, and \strut is even taller. Use \strut instead.
--
Best regards,
Vilar Camara Neto