1

The following code gives example pages from a style of book.

    \documentclass[a4paper]{book}
    \setlength\headheight{0cm}

    \usepackage{xcolor}
    \colorlet{headbgcolor}{green!50!blue!70}
    \setlength{\topmargin}{-1.5cm}
    \usepackage{fancyhdr}
    \pagestyle{fancy}
    \renewcommand\chaptermark[1]{\markboth{\chaptername\ \thechapter:\enskip#1}{}}
    \fancyhf{}

    \fancyhead[LE]{%
    \makebox[0pt][r]{
    \colorbox{headbgcolor}{\makebox[\textwidth][r]{\bfseries\textcolor{white}{\thepage}\enskip}}\hspace*{1em}}%
    {\itshape\leftmark}\hspace*{1em}\headrulefill%
    }
    \fancyhead[RO]{%
    \mbox{}\headrulefill \hspace*{1em}{\itshape\leftmark}%
    \makebox[0pt][l]{%
    \hspace*{1em}\colorbox{headbgcolor}{\makebox[\textwidth][l]{\enskip  \bfseries\textcolor{white}{\thepage}}}}%
     }
     \renewcommand\headrulewidth{0pt}

     \def\headrulefill{\leaders\hrule width 0pt height 3pt depth -2.8pt \hfill}

     \usepackage{blindtext}% dummy text

     \fancypagestyle{plain}{
     \fancyhf{}
     \fancyhead[LE]{%
     \makebox[0pt][r]{
     \colorbox{headbgcolor}{\makebox[\textwidth][r]{\bfseries \textcolor{white}{\thepage}\enskip}}\hspace*{1em}}%
{\itshape\leftmark}\hspace*{1em}\headrulefill%
     }
     \fancyhead[RO]{%
     \mbox{}\headrulefill \hspace*{1em}{\itshape\leftmark}%
     \makebox[0pt][l]{%
     \hspace*{1em}\colorbox{headbgcolor}{\makebox[\textwidth][l]{\enskip\bfseries\textcolor{white}{\thepage}}}}%
     }
     }
     \usepackage{mathptmx} 
     \begin{document}
     \blinddocument
     \end{document}

I was wondering if there is any way to increase the width of the blocks of text in this document class in the direction as indicated by arrows in the image below: enter image description here I've tried to use commands from the geometry package and \setlength{\rightmargin}{...} but to no avail. Any help appreciated. I have a feeling it will be something obvious I've missed...

  • 1
    Have you tried the width option of geometry? \usepackage[width=16cm]{geometry}. By the way, you should not write \setlength\headheight{0cm} since you obviously have a heading. – Eric Domenjoud Nov 22 '16 at 16:34
1

Instead of using

\setlength\headheight{0cm}
\setlength{\topmargin}{-1.5cm}

you should better use package geometry. From your screenshot I guess that the values topmargin tmargin=2cm, rightmargin rmargin=3cm and textwidth width=14cm are the values you need. If not chage them for your needs.

So adding the command

\usepackage[rmargin=3cm,tmargin=2cm,width=14cm]{geometry} % <===========

in your preamble should do what you want.

With the complete MWE

\documentclass[a4paper]{book}

%\setlength\headheight{0cm}
%\setlength{\topmargin}{-1.5cm}

\usepackage[rmargin=3cm,tmargin=2cm,width=14cm]{geometry} % <===========

\usepackage{xcolor}
    \colorlet{headbgcolor}{green!50!blue!70}

\usepackage{fancyhdr}
    \pagestyle{fancy}
    \renewcommand\chaptermark[1]{\markboth{\chaptername\ \thechapter:\enskip#1}{}}
    \fancyhf{}

    \fancyhead[LE]{%
    \makebox[0pt][r]{
    \colorbox{headbgcolor}{\makebox[\textwidth][r]{\bfseries\textcolor{white}{\thepage}\enskip}}\hspace*{1em}}%
    {\itshape\leftmark}\hspace*{1em}\headrulefill%
    }
    \fancyhead[RO]{%
    \mbox{}\headrulefill \hspace*{1em}{\itshape\leftmark}%
    \makebox[0pt][l]{%
    \hspace*{1em}\colorbox{headbgcolor}{\makebox[\textwidth][l]{\enskip  \bfseries\textcolor{white}{\thepage}}}}%
     }
     \renewcommand\headrulewidth{0pt}

     \def\headrulefill{\leaders\hrule width 0pt height 3pt depth -2.8pt \hfill}

\usepackage{blindtext}% dummy text

     \fancypagestyle{plain}{
     \fancyhf{}
     \fancyhead[LE]{%
     \makebox[0pt][r]{
     \colorbox{headbgcolor}{\makebox[\textwidth][r]{\bfseries \textcolor{white}{\thepage}\enskip}}\hspace*{1em}}%
{\itshape\leftmark}\hspace*{1em}\headrulefill%
     }
     \fancyhead[RO]{%
     \mbox{}\headrulefill \hspace*{1em}{\itshape\leftmark}%
     \makebox[0pt][l]{%
     \hspace*{1em}\colorbox{headbgcolor}{\makebox[\textwidth][l]{\enskip\bfseries\textcolor{white}{\thepage}}}}%
     }
     }
\usepackage{mathptmx} 


\begin{document}
  \blinddocument
\end{document}

I get the result:

resulting pdf

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.