如何重新激活节编号

如何重新激活节编号

我使用了一个较旧的序言,其中我关闭了特定页面和目录中的章节编号。现在,我正在为另一份文档使用它,但我无法重新激活它?我的错误在哪里?

这是我的 MWE:

\documentclass[a4paper,12pt]{scrreprt}
\usepackage[utf8x]{inputenc} % Eingabekodierung: UTF-8
\usepackage[T1]{fontenc} % ordentliche Trennung
\usepackage[ngerman]{babel}

\usepackage[top=2.5cm,bottom=3.5cm,left=2.5cm,right=4cm,headheight=14.5pt,footnotesep=1cm]{geometry}

\usepackage{setspace}

\usepackage[markcase=ignoreupper]{scrlayer-scrpage}
\clearpairofpagestyles
\automark[section]{section}



\usepackage{titlesec}
\titleformat{\section}[display]
{\normalfont\large\bfseries}
{\thesection}{14pt}{\large}

\titleformat{\subsection}[display]
{\normalfont\large\bfseries}
{\thesubsection}{14pt}{\large}


\newcommand{\nocontentsline}[3]{}
\newcommand{\tocless}[2]    {\bgroup\let\addcontentsline=\nocontentsline#1{#2}\egroup}

\usepackage{tocloft}
\renewcommand{\cfttoctitlefont}{\large\bfseries}
\renewcommand{\cftloftitlefont}{\normalfont\large\bfseries}
\renewcommand{\cftlottitlefont}{\normalfont\large\bfseries}
\renewcommand\cftbeforetoctitleskip{24pt}
\renewcommand\cftaftertoctitleskip{12pt}
\renewcommand\cftbeforeloftitleskip{24pt}
\renewcommand\cftafterloftitleskip{12pt}
\renewcommand\cftbeforelottitleskip{24pt}
\renewcommand\cftafterlottitleskip{12pt}
\renewcommand{\cftsecleader}{\cftdotfill{\cftdotsep}}

%\addtocontents{toc}{\cftpagenumbersoff{section}} 
\renewcommand{\cftdot}{}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


\begin{document}
\large\tableofcontents
\clearpage

\section{Section}
Some text.
\end{document}

答案1

建议使用类scrartcl(如您对问题的评论中所述)但不使用包titlesectocloft

\documentclass[a4paper,12pt]{scrartcl}
\usepackage[utf8]{inputenc} % <- use utf8 instead utf8x
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}

\usepackage[
  top=2.5cm,bottom=3.5cm,
  left=2.5cm,right=4cm,
  headheight=14.5pt,footnotesep=1cm
]{geometry}

\usepackage[automark]{scrlayer-scrpage}
\clearpairofpagestyles % no contents in page header and footer??

\addtokomafont{disposition}{\rmfamily}
\RedeclareSectionCommands[
  font=\large,
  toclinefill=\hfill
]{section,subsection}

% Roman numbers for sections and subsections
\renewcommand*\thesection{\Roman{section}}
\renewcommand*\thesubsection{\thesection.\Roman{subsection}}

% Section and subsection numbers in an extra line
\renewcommand*\sectionformat{\thesection\autodot\\*[14pt]}
\renewcommand*\subsectionformat{\thesubsection\autodot\\*[14pt]}

\makeatletter
\renewcommand*\sectionlinesformat[4]{%
  \ifstr{#1}{section}
    {#3#4}
    {\ifstr{#1}{subsection}
      {#3#4}
      {\@hangfrom{\hskip #2#3}{#4}}% original definition for other section levels
    }%
}
\makeatother

\usepackage{lipsum}% only for dummy text
\begin{document}
\tableofcontents
\clearpage

\section{Section}
\lipsum[1]
\subsection{A Subsection}
\lipsum
\end{document}

在此处输入图片描述

如果你确实想更改目录和列表中标题前后的分隔符,你可以添加

\BeforeTOCHead{%
  \vspace*{24pt}%
}
\AfterTOCHead{%
  \addvspace{12pt}%
}

回到序言。

相关内容