從標題中刪除“chapter”關鍵字

從標題中刪除“chapter”關鍵字

我的乳膠文檔的當前代碼是這樣的:

\documentclass[12pt,notitlepage]{report}

\usepackage{lipsum}  

\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhead{}
\fancyhead[C]{\nouppercase{\textit \leftmark}}

\begin{document}

\pagenumbering{roman}

\thispagestyle{plain}
\tableofcontents
\addcontentsline{toc}{chapter}{Table of Contents}
\thispagestyle{plain}

\newpage

\pagenumbering{arabic}
\chapter{One}
\lipsum[2-5]


\end{document}

我想刪除“第一章”。我的標題「第 1 章。一」中的關鍵字,我希望它是這樣的:「1-One」。怎麼做?

答案1

您可以重新定義\chaptermark

\renewcommand\chaptermark[1]{\markboth{\thechapter\,--\,#1}{}}

一個完整的例子:

\documentclass[12pt,notitlepage]{report}
\usepackage{lipsum}     
\usepackage{fancyhdr}

\pagestyle{fancy}
\fancyhead{}
\fancyhead[C]{\nouppercase{\textit{\leftmark}}}
\renewcommand\chaptermark[1]{\markboth{\thechapter\,--\,#1}{}}

\begin{document}

\pagenumbering{roman}

\thispagestyle{plain}
\tableofcontents
\addcontentsline{toc}{chapter}{Table of Contents}
\thispagestyle{plain}

\newpage

\pagenumbering{arabic}
\chapter{One}
\lipsum[2-5]

\end{document}

在此輸入影像描述

答案2

作為替代方案,fancyhdr您可以使用scrlayer-scrpage:

\documentclass[12pt,notitlepage]{report}

\usepackage{lipsum}  

\usepackage[pagestyleset=KOMA-Script,headsepline,automark]{scrlayer-scrpage}
\setkomafont{pagehead}{\itshape}% use italic instead of slanted page header
\renewcommand*{\chaptermarkformat}{\thechapter--}% Use "1–" instead of "Chapter 1 " in the chapter mark
\begin{document}

\pagenumbering{roman}

\cleardoublepage
\addcontentsline{toc}{chapter}{Table of Contents}% Has to be at the begin of
                                % the first ToC page (before \tableofcontents)
\tableofcontents

\cleardoublepage% if twoside next odd page

\pagenumbering{arabic}
\chapter{One}
\lipsum[2-5]

\end{document}

使用 scrlayer-scrpage

注意:我還刪除了奇怪的\thispagestyle{plain}命令並移動了該\addcontentsline命令。在您的範例中,它將把目錄的最後一頁添加到目錄中,這是沒有意義的。

作為替代方案,您可以使用套件tocbibind

但是,我建議不要將目錄條目新增至目錄。大多數情況下,這沒有任何意義。

答案3

一個簡單的可能性是加載titleps,它是附帶的titlesec,但可以獨立使用。不要擺弄標記(除非你想…)。只是\chaptertitle,,\sectiontitle等等)。

\documentclass[12pt,notitlepage]{report}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lipsum}
\usepackage{titleps}

\newpagestyle{mypagestyle}{%
\headrule
\sethead{}{\textit{\thechapter.\,–\,\chaptertitle}}{}
\setfoot{}{\thepage}{}
}%

\begin{document}

\pagenumbering{roman}

\thispagestyle{plain}
\tableofcontents
\addcontentsline{toc}{chapter}{Table of Contents}

\newpage

\pagestyle{mypagestyle}
\pagenumbering{arabic}
\chapter{One}
\lipsum

\end{document} 

在此輸入影像描述

相關內容