3

The current code for my latex document is this:

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

I want to remove the "Chapter 1." keyword from my header "Chapter 1. One" and I want it like this: "1-One". How to do it?

3 Answers 3

5

You can redefine \chaptermark as in

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

A complete example:

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

enter image description here

3

As an alternative to fancyhdr you can use 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}

Using scrlayer-scrpage

Note: I've also removed strange \thispagestyle{plain} commands and moved the \addcontentsline command. In you example, it would add the last page of the table of contents to the table of contents, which wouldn't make sense.

As an alternative you could use package tocbibind.

However, I would recommend not to add an entry for the table of contents into the table of contents. Mostly this doesn't make any sense.

2

A simple possibility is to load titleps, which comes with titlesec but can be used independently. No fiddling with marks (unless you want to…). Just \chaptertitle, \sectiontitle, &c.).

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

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .