
Текущий код моего документа 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}
Я хочу удалить ключевое слово "Глава 1." из моего заголовка "Глава 1. Одна" и хочу, чтобы было так: "1-Один". Как это сделать?
решение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}
Примечание: Я также удалил странные \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}