[Tex/LaTex] New chapter command for attachment

chapterssectioning

I am searching a solution to change the definition of the chapter command before putting the attachment in my document, which is a scrreprt.

With the scrreprt class, my normal chapters have only a number and then the title.
My goal would be to let that as it is for the normal chapters, then, when I begin the attachment part, that my chapters have an other layout: simply the words "attachment" before the numbering, like "Attachment 1. Title of this attachment".

It should have the same behaviour in the table of contents: normal chapters should just be numeroted as usual and then the ones in the attachment part should have the word attachment before.

I already tried some things, I think it should be possible with a \renewcommand at the begin of the attachment part, or maybe a \newcommand named for instance \attachment based on the \chapter command, but I don't understand how it works.

Could someone please help me?

If I write a minimal exemple I have something like:

\documentclass[11pt,a4paper]{scrreprt}
\usepackage[ngerman]{babel}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage[T1]{fontenc}

\begin{document}
\tableofcontents
\part{First Part}
\chapter{Title of chapter 1}
\chapter{Title of chapter 2}
\part{Attachment}
\chapter{Title of attachment 1}
\chapter{Title of attachment 2}
\end{document}

Thank you forward for your help, sorry for my bad english and have a nice day/evening/something 😉

Best Answer

Based on the great answer of esdd you can use the following code in your preamble:

\newcommand\tocappendixnumber[1]{\chapapp~#1}
\newcommand\startattachment{%
  \addtocontents{toc}{%
   \RedeclareSectionCommand[
      tocdynnumwidth,
      tocentrynumberformat=\tocappendixnumber
    ]{chapter}}
  \renewcommand*{\chapterformat}{%
    \mbox{\chapappifchapterprefix{\nobreakspace}\chapapp~\thechapter\autodot
      \IfUsePrefixLine{}{\enskip}}%
  }
}

After \part{Attachment} use \startattachment

Related Question