ヘッダーから「章」キーワードを削除します

ヘッダーから「章」キーワードを削除します

私の LaTeX ドキュメントの現在のコードは次のとおりです。

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

ヘッダー「Chapter 1. One」から「Chapter 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

代わりにfancyhdrscrlayer-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} 

ここに画像の説明を入力してください

関連情報