我正在尝试让我的文档不包含警告。其中之一是
Usage of package `titlesec' together(scrreprt) with a KOMA-Script class is not recommended.
Non standard sectioning command detected(titlesec) Using default spacing and no format.
我已经更改了布局,所以不再使用 titleformat。但是如果没有 \usepackage{titlesec},代码仍然无法工作。我遗漏了什么?
\documentclass[11pt, a4paper]{scrreprt}
\usepackage{blindtext}
\usepackage{xcolor}
\usepackage{titlesec}
%\usepackage[headsepline, automark]{scrlayer-scrpage}
% \titleformat{\chapter}[display] % {command}[shape]
% {\usekomafont{chapter}\filcenter} % format
% { % label
% {\fcolorbox{black}{shadecolor}{
% {\huge\chaptertitlename\mbox{\hspace{1mm}}\thechapter}
% }}}
% {1pc} % sep (from chapternumber)
% {\vspace{1pc}} % {before}[after] (before chaptertitle and after)
\KOMAoptions{chapterprefix}
\renewcommand{\chapterheadmidvskip}{%
\vspace{12pt}
}
\setkomafont{chapter}{\Large\color{black}}
\renewcommand{\chapterlineswithprefixformat}[3]{%
\parbox{\dimexpr\linewidth-2\fboxrule-2\fboxsep}{%
#2 \vspace{.9pc}
\hrule height 1pt \vspace{2pc}
#3 \vspace{1.2pc}\hrule height 1pt%
}
}
\renewcommand{\chapterheadmidvskip}{}
\renewcommand{\chapterformat}{%
\mbox{\LARGE\MakeUppercase{Kapitel}\Huge~\thechapter\filright%
}
}
\begin{document}
\chapter{test}
\blindtext
\end{document}
答案1
正如@campa 在评论中提到的那样,\filright
它是由包定义的titlesec
。
以下是一些额外的建议:不要重新定义\chapterheadmidvskip
(这在您的 MWE 中已完成两次)。而是innerskip
使用进行设置。在 的重新定义中\RedeclareSectionCommand
添加。\raggedchapter
\parbox
\chapterlineswithprefixformat
\documentclass[ngerman]{scrreprt}% 11pt and paper=a4 are default
\usepackage{blindtext}
\usepackage{xcolor}
\usepackage{babel}
\usepackage[headsepline, automark]{scrlayer-scrpage}
\KOMAoptions{chapterprefix}
\RedeclareSectionCommand[
innerskip=0pt,
font=\Large\color{black},
prefixfont=\LARGE
]{chapter}
\renewcommand{\chapterlineswithprefixformat}[3]{%
\ifstr{#1}{chapter}{% <- change the layout for chapters
\parbox{\dimexpr\linewidth-2\fboxrule-2\fboxsep}{%
\raggedchapter% <- added (default meaning is \raggedright)
#2 \vspace{.9pc}
\hrule height 1pt \vspace{2pc}
#3 \vspace{1.2pc}\hrule height 1pt%
}%
}{%
#2#3% original definition for other levels with style=chapter
}
}
\renewcommand{\chapterformat}{%
\MakeUppercase{\chaptername}\Huge~\thechapter
}
\begin{document}
\chapter{test}
\blindtext
\Blinddocument
\end{document}