Fancyhdr 标题:标题上出现章节、小节和小节

Fancyhdr 标题:标题上出现章节、小节和小节

我正在尝试创建一个具有特定标题的 LaTeX 模板。以下是我想做的事情:

  • 左奇数:\subsubsection
  • 真奇怪:我的名字,我可以处理这个:)
  • 左偶数:\subsection
  • 甚至正确:\chapter

对于每个标题,我只想要标题,而不是“第 1 章:章节名称”。

我用过这个:

\renewcommand{\subsectionmark}[1]{\markright{#1}}
\renewcommand{\subsubsectionmark}[1]{\markleft{#1}}

但它只适用于两个标题,对吗?

这是我的代码:

\documentclass[12pt,twoside]{book}
\usepackage{fontspec}
\usepackage{lipsum}

\setmainfont{[ACaslonPro-Regular.otf]}
\newfontfamily{\acasSb}{ACaslonPro-Semibold.otf}
\newfontfamily{\acasB}{ACaslonPro-Bold.otf}
\newfontfamily{\acasR}{ACaslonPro-Regular.otf}

\newfontfamily{\frutL}{FrutigerLTStd-Light.otf}
\newfontfamily{\frutB}{FrutigerLTStd-Bold.otf}
\newfontfamily{\frutR}{FrutigerLTStd-Roman.otf}


\usepackage[paperheight=240mm,paperwidth=160mm, left=22mm, right = 20mm, top = 20mm, bottom = 22mm]{geometry}

\usepackage{fancyhdr}
\pagestyle{fancy}

\renewcommand{\subsectionmark}[1]{\markright{#1}}
\renewcommand{\subsubsectionmark}[1]{\markleft{#1}}

\fancyhead[LO]{\fontsize{8}{12} \selectfont \acasB \textsc{\rightmark}}
\fancyhead[RO]{}
\fancyhead[C]{}
\fancyhead[LE]{\fontsize{8}{12} \selectfont \acasB \rightmark}
\fancyhead[RE]{\fontsize{8}{12} \selectfont \acasB \textsc{\leftmark}}


\begin{document}

\chapter{This should be on right even}
\section{This should not appear at all}
\subsection{This should be on left even}
\subsubsection{This should be on odd left}

\lipsum[1-8]
\end{document}

感谢您的帮助

答案1

以下是我找到的解决方案:

\documentclass[12pt,twoside]{book}
\usepackage{fontspec}
\usepackage{lipsum}

\setmainfont{[ACaslonPro-Regular.otf]}
\newfontfamily{\acasSb}{ACaslonPro-Semibold.otf}
\newfontfamily{\acasB}{ACaslonPro-Bold.otf}
\newfontfamily{\acasR}{ACaslonPro-Regular.otf}

\newfontfamily{\frutL}{FrutigerLTStd-Light.otf}
\newfontfamily{\frutB}{FrutigerLTStd-Bold.otf}
\newfontfamily{\frutR}{FrutigerLTStd-Roman.otf}


\usepackage[paperheight=240mm,paperwidth=160mm, left=22mm, right = 20mm, top = 20mm, bottom = 22mm]{geometry}

\usepackage{fancyhdr}
\pagestyle{fancy}

\renewcommand{\chaptermark}[1]{\markboth{#1}{}}

\let\Subsubsectionmark\subsubsectionmark
\def\subsubsectionmark#1{\def\Subsubsectionname{#1}\Subsubsectionmark{#1}}

\let\Subsectionmark\subsectionmark
\def\subsectionmark#1{\def\Subsectionname{#1}\Subsectionmark{#1}}




\fancyhead[LO]{\fontsize{8}{12} \selectfont \acasB \textsc{\Subsubsectionname}}
\fancyhead[RO]{}
\fancyhead[C]{}
\fancyhead[LE]{\fontsize{8}{12} \selectfont \acasB \Subsectionname}
\fancyhead[RE]{\fontsize{8}{12} \selectfont \acasB \textsc{\leftmark}}


\begin{document}

\chapter{This should be on right even}
\section{This should not appear at all}
\subsection{This should be on left even}
\subsubsection{This should be on odd left}

\lipsum[1-8]



\end{document}

唯一的缺点是:似乎我无法在 \leftmark 上使用 \textsc 来获得小写章节名称。如果有人知道如何处理这个问题,我将不胜感激!

相关内容