-1

In my table of contents I would like to insert a "Chapter 1:", "Chapter 2:", etc. with the chapters after the introduction: \mychapter{2}{Title} and then goes on. It should be in the same line.

Additionally, would it also be possible to put it in the header above each \mychapter{2}{TITLE}, \mychapter{3}{TITLE}, \mychapter{4}{TITLE} ?

This is my document class:

\documentclass[12pt,openany]{scrreprt}

A reason for using \mychapter was that the number which is usually displayed before every chapter gets deleted.

Is it possible to do this?

esdd
  • 85,675
Karl L.
  • 325
  • 2
    What is this \mychapter command? – Vincent Feb 27 '20 at 22:53
  • Usually there is a 1 Introduction when you use \chapter, but by using \mychapter, the number is deleted in front of it. – Karl L. Feb 27 '20 at 22:59
  • Please show the definition of \mychapter. – esdd Feb 27 '20 at 23:02
  • Usually when \chapter is used there is a number before the title (1 Introduction). By using \mychapter instead of \chapter the number disappears. – Karl L. Feb 27 '20 at 23:02
  • I just copy pasted it from somewhere on the internet. I myself don't understand it:\newcommand{\mychapter}[2]{ \setcounter{chapter}{#1} \setcounter{section}{0} \chapter*{#2} \addcontentsline{toc}{chapter}{#2} – Karl L. Feb 27 '20 at 23:03
  • this is everything I got :/ – Karl L. Feb 27 '20 at 23:07
  • https://tex.stackexchange.com/questions/25030/chapter-number-and-chapter-title-in-one-line would it be possible to transfer this to \mychapter? – Karl L. Feb 27 '20 at 23:10

1 Answers1

3

If the number of the chapter should not be displayed in the headings use

\renewcommand*{\chapterformat}{}

But if you want a prefix line for the chapter headings use class option chapterprefix and

\renewcommand*{\chapterformat}{%
  \mbox{\chapappifchapterprefix{\nobreakspace}\thechapter\autodot:
    \IfUsePrefixLine{}{\enskip}}%
}

to add the colon after the number.

To change the format of the entry in the page header use

\renewcommand*{\chaptermarkformat}{\chapapp\ \thechapter\autodot:\enskip}

and for the TOC entry

\let\originaladdchaptertocentry\addchaptertocentry
\renewcommand*{\addchaptertocentry}[2]{%
  \IfArgIsEmpty{#1}
    {\originaladdchaptertocentry{#1}{#2}}
    {\originaladdchaptertocentry{\chapappifchapterprefix{\nobreakspace}#1\autodot}{#2}}%
}
\RedeclareSectionCommand[
  tocentrynumberformat={\def\autodot{:}},
  tocdynnumwidth
]{chapter}

Example:

\documentclass[
  12pt,
  chapterprefix,% use a prefix line for chapters
  numbers=noenddot% no dot at the end of numbers
]{scrreprt}
\usepackage{lipsum}% only for dummy text
\pagestyle{headings}

\renewcommand*{\chapterformat}{%
  \mbox{\chapappifchapterprefix{\nobreakspace}\thechapter\autodot:
    \IfUsePrefixLine{}{\enskip}}%
}
\renewcommand*{\raggedchapter}{\centering}
\renewcommand*{\chaptermarkformat}{\chapappifchapterprefix{\nobreakspace}\thechapter\autodot:\enskip}

\let\originaladdchaptertocentry\addchaptertocentry
\renewcommand*{\addchaptertocentry}[2]{%
  \IfArgIsEmpty{#1}
    {\originaladdchaptertocentry{#1}{#2}}
    {\originaladdchaptertocentry{\chapappifchapterprefix{\nobreakspace}#1\autodot}{#2}}%
}
\RedeclareSectionCommand[
  tocentrynumberformat={\def\autodot{:}},
  tocdynnumwidth
]{chapter}

\begin{document}
\tableofcontents
\chapter{Foo}
\lipsum
\appendix
\chapter{Bar}
\lipsum
\end{document}

Run three times to get

enter image description here

esdd
  • 85,675
  • thank you so much! How can I also display Chapter 1 above the title of the page itself? – Karl L. Feb 27 '20 at 23:26
  • See my updated answer. – esdd Feb 27 '20 at 23:35
  • I think I did not really understand it. Now I removed all my \mychapters and replaced them with \chapter ... however my appendix should not be displayed as Chapter No. : Appendix in the toc. How can I remove the chapter here? – Karl L. Feb 27 '20 at 23:36
  • also how can I center "chapter: title"? As it is displayed on the left side of the page? – Karl L. Feb 27 '20 at 23:43
  • Could you please give an example on how to not display the "chapter number" in the toc but the title. E.g. I would like my Appendix not to have a chapter + number (neither displayed on the page). but set the counter from a specific \chapter. – Karl L. Feb 28 '20 at 00:01
  • 2
    There was not an appendix in your question, but I have updated my answer again. To center the chapter heading you can use \renewcommand*{\raggedchapter}{\centering}. Please ask a new question (including a minimal working example) if there are other issues. – esdd Feb 28 '20 at 00:02
  • thanks! Sorry for asking so much! – Karl L. Feb 28 '20 at 00:05
  • https://tex.stackexchange.com/questions/530323/how-to-remove-chapter-number-in-the-toc-and-on-the-page-itself-from-particu would you please be so kind and help me out? – Karl L. Feb 28 '20 at 01:43