1

Originally was my code in article class. In the footer it showed the name and number of the section (which was the chapter) in the way it was formatted e.g. bold etc....

However converting it over to book class, it no longer shows the name of the chapter, but instead the name of the section. here is the MWE:

\documentclass[12pt, oneside]{book}

\usepackage{sectsty,fancyhdr}
\usepackage{geometry}

\usepackage{lipsum}%remove 

% ***************************Header/Footer Settings****************************

\sectionfont{\LARGE\bfseries}
\pagestyle{fancy}
\fancyhf{}
\rhead{} 
\lhead{Project title} 
\renewcommand{\headrulewidth}{2.0pt} 
\renewcommand{\footrulewidth}{1.0pt} 
\setlength{\headheight}{14.5pt}
\rfoot{Page \thepage}  
\lfoot{\chaptername~\thechapter} 
%\lfoot{\leftmark} % Should show the name and style of chapter




\makeatletter
\renewcommand{\sectionmark}[1]{%this avoids the \makecaptical of footers
    \markboth{\ifnum \c@secnumdepth>\z@ %this allowes symbols in foorters
  \thesection\hskip 1em\relax
\fi #1}{}}
\makeatother

% ***************************Chapter Style****************************

     \usepackage{graphicx} 
     \usepackage{etoolbox}

    \makeatletter   
    % no new page for \chapter
    \patchcmd{\chapter}{\if@openright\cleardoublepage\else\clearpage\fi}{}{}{}
    % don't change the pagestyle
    \patchcmd{\chapter}{\thispagestyle{plain}}{}{}{%
    \GenericWarning{(preamble)\@spaces\@spaces\@spaces\@spaces}{Package preamble Warning: patching \string\chapter\space did not work.}}

    % allow floats on new chap page
    \patchcmd{\chapter}{\global\@topnum\z@}{}{}{}

    %style 

     \usepackage[T1]{fontenc}
     \usepackage{titlesec,xcolor}

    \definecolor{gray75}{gray}{0.65} 
    \newcommand{\hsp}{\hspace{20pt}}
    \titleformat{\chapter}[hang]{\vspace*{-2em}\Huge\bfseries}{\scalebox{1}    {\thechapter}\hsp\textcolor{gray75}{|}\hsp}{0pt}{}  
    \titlespacing{\chapter}{0pt}{50pt}{30pt} 

 %------------------------------Begin--------------------------------
\begin{document}

 \chapter{Example 1}
 \section{Section 1}
 \lipsum

 \newpage 
 \chapter{Example 2}
 \section{Section 2}
 \lipsum

\end{document}

How to make it so that it shows "1 Example" with the grey vertical line in the footer.

0

You should be changing \chaptermark rather than \sectionmark. With \lfoot{\leftmark} the following is appropriate:

\renewcommand{\chaptermark}[1]{\markboth{\thechapter\ \textcolor{gray75}{|} #1}{}}

Sample output

\documentclass[12pt, oneside]{book}

\usepackage{sectsty,fancyhdr}
\usepackage{geometry}

\usepackage{lipsum} %remove

% ***************************Header/Footer Settings****************************

\sectionfont{\LARGE\bfseries}
\pagestyle{fancy}
\fancyhf{}
\rhead{}
\lhead{Project title}
\renewcommand{\headrulewidth}{2.0pt}
\renewcommand{\footrulewidth}{1.0pt}
\setlength{\headheight}{14.5pt}
\rfoot{Page \thepage}
\lfoot{\leftmark} % Should show the name and style of chapter

\renewcommand{\chaptermark}[1]{\markboth{\thechapter\ \textcolor{gray75}{|} #1}{}}

% ***************************Chapter Style****************************

\usepackage{graphicx}
\usepackage{etoolbox}

\makeatletter
% no new page for \chapter
\patchcmd{\chapter}{\if@openright\cleardoublepage\else\clearpage\fi}{}{}{}
% don't change the pagestyle
\patchcmd{\chapter}{\thispagestyle{plain}}{}{}{%
\GenericWarning{(preamble)\@spaces\@spaces\@spaces\@spaces}{Package preamble Warning: patching \string\chapter\space did not work.}}

% allow floats on new chap page
\patchcmd{\chapter}{\global\@topnum\z@}{}{}{}

% style

\usepackage[T1]{fontenc}
\usepackage{titlesec,xcolor}

\definecolor{gray75}{gray}{0.65}
\newcommand{\hsp}{\hspace{20pt}}
\titleformat{\chapter}[hang]{\vspace*{-2em}\Huge\bfseries}{\scalebox{1}{\thechapter}\hsp\textcolor{gray75}{|}\hsp}{0pt}{}
\titlespacing{\chapter}{0pt}{50pt}{30pt}

% ------------------------------Begin--------------------------------
\begin{document}

\chapter{Example 1}
\section{Section 1}
\lipsum

\newpage
\chapter{Example 2}
\section{Section 2}
\lipsum

\end{document}
  • This worked perfectly thank you. Out of curiosity were did you learn most of your Latex from. Do you have any resources which will allow me to improve? – Tutorz Oct 19 '17 at 11:49
  • For learning resources see tex.stackexchange.com/q/11/15925 and other related questions. – Andrew Swann Oct 19 '17 at 14:05

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.