0

I was given the following code for creating a "chapter" on top of the page, followed by the "title" of the page, which is displayed below "chapter".

This is the document class I use:

\documentclass[chapterprefix]{scrreprt}

I have the following problem: I would like only particular \chapters to display "chapter: [number]" in the toc before a "title". The title should still be displayed just without "chapter: [number]". Right now all my \chapters display a chapter: [number] in front of the title in the toc and on the page.

Also, how to I remove the colons that appear after "Chapter[:]" on the page (but leave them in the table of contents)?

Additionally, by applying the \documentclass that was given to me something changed. I don't know whether the font got smaller but my pages shrank from about 60 to 54. Any idea?

\pagestyle{headings} %chapter in toc and on page (numbering)

\renewcommand*{\chapterformat}{%
  \mbox{\chapappifchapterprefix{\nobreakspace}\thechapter\autodot:
    \IfUsePrefixLine{}{\enskip}}%
}
\renewcommand*{\chaptermarkformat}{\chapapp\ \thechapter\autodot:\enskip}
\RedeclareSectionCommand[
  tocentrynumberformat=\tocentrywithprefix{\chapapp},
  tocdynnumwidth
]{chapter}
\newcommand\tocentrywithprefix[2]{\mbox{#1~#2:}}
\renewcommand*{\raggedchapter}{\centering}

  • 1
    For the number of pages that shrank, in your last post you used the option 12pt with the class scrreprt, but here you removed it. Maybe it's only that the font size shrank from 12pt to 11pt. You could try to put the option 12pt back. – Vincent Feb 28 at 0:35
  • \documentclass[chapterprefix][12pt]{scrreprt} Latex displays an error if I do it like that. – Karl L. Feb 28 at 0:40
  • Try \documentclass[12pt,chapterprefix]{scrreprt}. – Vincent Feb 28 at 0:42
  • thanks it worked! Unfortunately, I still haven't worked out my main problem – Karl L. Feb 28 at 0:57
1

To remove the : from the chapter heading, remove the redefinition of \chapterformat. It was only redefined to add the colon.

Unfortunaly I do not understand what you really want to do.

If the prefix should be removed only in appendix, you can use

\documentclass[
  12pt,
  chapterprefix,
  %appendixprefix=false,% no prefixline for appendix chapters
  numbers=noenddot
]{scrreprt}
\usepackage{lipsum}% only for dummy text
\pagestyle{headings}

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

\let\originalappendix\appendix
\renewcommand*{\appendix}{%
  \originalappendix
  %\renewcommand*\chapterformat{}% remove the chapter number  from chapter heading
  %\renewcommand*\chaptermarkformat{}% remove the chapter number from header entry
  \renewcommand*{\addchaptertocentry}[2]{% remove the chapter number from ToC entry
    \originaladdchaptertocentry{}{##2}%
  }%
}

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

Run three times to get

enter image description here

If you only want to use unnumbered chapters with ToC and header entry, replace \chapter by \addchap:

\documentclass[
  12pt,
  chapterprefix,
  numbers=noenddot
]{scrreprt}
\usepackage{lipsum}% only for dummy text
\pagestyle{headings}

\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
\addchap{Introduction}% unnumbered chapter
\lipsum
\chapter{Foo}% numbered chapter
\lipsum
\appendix
\addchap{Bar}% unnumbered chapter
\lipsum
\chapter{Numbered}% numbered chapter
\end{document}

enter image description here

| improve this answer | |
  • Thank you very much, again! This was just what I needed – Karl L. Feb 28 at 10:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.