书籍类中的页脚 \leftmark 未显示章节名称和样式

书籍类中的页脚 \leftmark 未显示章节名称和样式

最初我的代码是在文章类中。在页脚中,它以格式化的方式(例如粗体等)显示了部分(即章节)的名称和编号……

但是将其转换为书籍类时,它不再显示章节的名称,而是显示部分的名称。这是 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}

如何使其在页脚中显示带有灰色垂直线的“1 个示例”。

答案1

您应该更改\chaptermark而不是\sectionmark\lfoot{\leftmark}以下内容是合适的:

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

示例输出

\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}

相关内容