如何在页脚中插入部分名称而不保留部分名称格式?

如何在页脚中插入部分名称而不保留部分名称格式?

我用于文章格式的页眉和页脚的代码如下:

\usepackage{fancyhdr}

\pagestyle{fancy}
\fancyhf{}
\rhead{}
\lhead{Project tile}
\renewcommand{\headrulewidth}{2.0pt}
\renewcommand{\footrulewidth}{1.0pt} 
\rfoot{Page \thepage}
\lfoot{\leftmark}

问题是,这也会打印出我为使其脱颖而出而对部分名称所设置的格式:

\section{\LARGE{\textbf{Introduction}}}

这只会增加尺寸,并使部分名称变粗。那么,如何将当前部分名称放在页脚中,而不使页脚名称也变大变粗呢?

答案1

您采用的方法错误。您应该避免在标题内设置分段格式,因为这会影响标记(通常用于页眉/页脚)以及目录,这并不理想。

相反,使用类似sectsty格式化分段字体(见更改章节、小节、小小节、段落和小段落标题的大小):

在此处输入图片描述

\documentclass{article}

\usepackage{sectsty,fancyhdr}
\sectionfont{\LARGE\bfseries}% https://tex.stackexchange.com/q/59726/5764

\pagestyle{fancy}
\fancyhf{}
\lhead{Project tile}
\renewcommand{\headrulewidth}{2.0pt}
\renewcommand{\footrulewidth}{1.0pt} 
\rfoot{Page \thepage}
\lfoot{\leftmark}

\makeatletter
\renewcommand{\sectionmark}[1]{%
  \markboth{\ifnum \c@secnumdepth>\z@
      \thesection\hskip 1em\relax
    \fi #1}{}}
\makeatother

\begin{document}

\tableofcontents

\section{Introduction}

\end{document}

上面我还更新了\sectionmark宏以避免\MakeUppercase作为默认构造的一部分插入。如有必要,您可以将其删除。

答案2

如果您使用 KOMA 类(scrartcl 等等),您可以不使用 fancyhdr 而是使用 scrlayer-scrpage 来完成此操作。

\documentclass{scrartcl}

\usepackage{scrlayer-scrpage}
\usepackage{lipsum}

\setkomafont{section}{<formatting>}% changes the formatting of headlines
\KOMAoptions{%
    headsepline=2pt,
    footsepline=1pt
}

\ihead{Project title}
\chead{}% if you leave this out the pagehead will contain the sectionnames, too
\ifoot{\headmark}% the i is for inner side of the page if you use twoside and left side if you use oneside
\cfoot{}% if you leave this out the pagenumber will be in the center, too
\ofoot{Page \pagemark}
\automark[section]{section}
\pagestyle{scrheadings}

\begin{document}
\section{foo}
\lipsum[1-10]
\end{document}

您可以使用 \cfoot 或 \ofoot 替代 \ifoot。如果您希望它们位于头部,则只需使用 \ihead、\chead 或 \ohead。

编辑:添加了头部和脚部分界线。

相关内容