[Tex/LaTex] Remove last dot in title numbering

appendiceschaptersformattingkoma-scriptpunctuation

My current document is processed like this:

1. Some chapter
1.1. Some section
1.1.1. Some subsection

Appendix A.
Some appendix

What I want to have:

1 Some chapter
1.1 Some section
1.1.1 Some subsection

Appendix A: Some appendix

So I want the last dots of the numbering removed for the main part. For the appendix, I want a colon instead of the dot and the title in the same line.

A small example, including all packages used:

\documentclass[appendixprefix=true,11pt,a4paper]{scrreprt}
%The packages used in my document
\usepackage{listings}
\usepackage{mathtools}
\usepackage{graphicx}
\usepackage{enumitem}
\usepackage{chngcntr}
\usepackage[usenames,dvipsnames]{color}
%Appendix definition (Write "Appendix A")
\makeatletter
\newcommand\appendix@numberline[1]{\appendixname\ #1: }
\g@addto@macro\appendix{%
  \addtocontents{toc}{
    \let\protect\numberline\protect\appendix@numberline}%
}
\makeatother

\begin{document}
\chapter{First chapter}
\section{First section}
\subsection{First subsection}
\appendix
\chapter{Last chapter}
\end{document}

How can I make the colon and the title in the same line. And how do I remove the last dots of the titles?


Symbol1's answer doesn't work. Error message:

Undefined control sequence. \@makechapterhead ...mdepth >\m@ne \if@mainmatter
\huge \bfseries \@chapapp ... l.108 \chapter{Definition of the Problem}

Best Answer

Here's how you can obtain the output you're after in the KOMA-script classes:

enter image description here

\documentclass[appendixprefix=true]{scrreprt}

\usepackage{etoolbox}
\makeatletter
\g@addto@macro{\appendix}{%
  \patchcmd{\@@makechapterhead}% <cmd>
    {\endgraf\nobreak\vskip.5\baselineskip}% <search>
    {\hspace*{-.5em}:\space}% <replace>
    {}{}% <success><failure>
  \patchcmd{\@chapter}% <cmd>
    {\addchaptertocentry{\thechapter}}% <search>
    {\addchaptertocentry{Appendix~\thechapter:}}% <replace>
    {}{}% <success><failure>
  \addtocontents{toc}{%
    \protect\patchcmd{\protect\l@chapter}% <cmd>
      {1.5em}% <search>
      {6.5em}% <replace>
      {}{}}% <success><failure>
}
\renewcommand{\autodot}{}% Remove all end-of-counter dots
\makeatother

\begin{document}

\tableofcontents

\chapter{First chapter}
\section{First section}
\subsection{First subsection}

\appendix
\chapter{Last chapter}

\end{document}

The dots are removed through a redefinition of \autodot, while the Appendix formatting is done via a \patchcmd of \@@makechapterhead when you call \appendix. The final patch adjusts the width of the \numberline box from 1.5em to 6.5em. This adjustment is specific to the chapter-related entry in the ToC as it deals with \l@chapter.

etoolbox provides the patching capability.