[Tex/LaTex] renewcommand chapter

chaptersheader-footer

Just a short question:
I want to renew the chapter command, so that I can manipulate the distance between the chapter number and the chapter title in my header, currently I have defined my header as:

\renewcommand{\chaptername}{}
\fancyhead[L]{\hspace{4mm}\textcolor{headercolor}{\leftmark}\\ \text{ }\textcolor{headercolor}{\hspace{0.4cm}\rightmark}\hfill\textcolor{headercolor}{}\hspace{2mm}}
\renewcommand{\headrule}{\vspace{-\headheight}\textcolor{headercolor}{\vrule height \headheight width 2pt\relax\rule{\textwidth}{2pt}\vrule height \headheight width 2pt\relax}}

now I want to change the chaptermark/chaptername, so that I can manipulate the distance between the number and the title.

E.g. currently it says 1. INTRODUCTION
but I want the space between 1. and INTRODUCTION to increase?

I know this is not a working example, but I hope you get it fast what I mean.

Best Answer

KOMA-Script

It is quite easy with the KOMA-Script classes. There macro \chaptermarkformat sets the chapter number in the headings and can be redefined, e.g.:

\documentclass{scrbook}

\makeatletter
\g@addto@macro{\chaptermarkformat}{\hspace{1em}}
\makeatother

\pagestyle{headings}

\begin{document}
\chapter{First chapter}
\newpage
Some text.
\end{document}

(\g@addto@macro{\cmd}{stuff} appends stuff to parameterless macro cmd).

Package fancyhdr

With package fancyhdr or the standard classes the distance is hardcoded in \chaptermark that is defined in the page style command. Therefore it becomes uglier, because also the page style command needs to be redefined, e.g.:

\documentclass{book}

\usepackage{fancyhdr}

\newlength{\marknumsep}
\setlength{\marknumsep}{1.5em}% Change to your needs

\makeatletter
\def\ps@fancy{%
  \@ifundefined{@chapapp}{\let\@chapapp\chaptername}{}%
  \@ifundefined{MakeUppercase}{\def\MakeUppercase{\uppercase}}{}%
  \@ifundefined{chapter}{%
    \def\sectionmark##1{%
      \markboth{%
        \MakeUppercase{%
          \ifnum \c@secnumdepth>\z@
            % \thesection\hskip 1em\relax % ORIGNAL
            \thesection\hskip\marknumsep % NEW
          \fi
          ##1%
        }%
      }{}%
    }%
    \def\subsectionmark##1{%
      \markright{%
        \ifnum \c@secnumdepth >\@ne
          % \thesubsection\hskip 1em\relax % ORIGINAL
          \thesubsection\hskip\marknumsep % NEW
        \fi
        ##1%
      }%
    }%  
  }{%
    \def\chaptermark##1{%
      \markboth{%
        \MakeUppercase{%
          \ifnum \c@secnumdepth>\m@ne
            % \@chapapp\ \thechapter. \ % ORIGINAL
            \thechapter\hskip\marknumsep % NEW
          \fi
           ##1%
        }%
      }{}%
    }%
    \def\sectionmark##1{%
      \markright{%
        \MakeUppercase{%
          \ifnum \c@secnumdepth >\z@
            % \thesection. \ % ORIGINAL
            \thesection.\hskip\marknumsep % NEW
          \fi
          ##1%
        }%
      }%  
    }%    
  }%      
  \ps@@fancy
  \gdef\ps@fancy{\@fancyplainfalse\ps@@fancy}%
  \ifdim\headwidth<0sp
    \global\advance\headwidth123456789sp%
    \global\advance\headwidth\textwidth  
  \fi
}
\makeatother

\pagestyle{fancy}

\begin{document}
\chapter{First chapter}
\newpage
Some text.
\end{document}

Now the distance between number and text in the headings can be controlled by the length \marknumsep. Also the example has removed the "Chapter"/"Appendix" prefix (\@chapapp).