更改章节样式,添加章节和 koma-script 列表问题

更改章节样式,添加章节和 koma-script 列表问题

我在重新定义章节样式时遇到了问题。我为此使用了\makechapterhead\makeschapterhead,但我无法使其与一起使用\addchap。上部的章节名称应如下所示:

全粗线(不是“第 0 章”)

全粗线(正确)

粗线“第 1 章” 粗线(正确)

粗线“第 2 章” 粗线(正确)

全粗线(不是“第 2 章”)

实线(不是“附录”)

我怎样才能做到这一点?

\documentclass[paper=a4, pagesize=auto, fontsize = 12pt]{scrbook}
\usepackage[T1]{fontenc}                
\usepackage[utf8]{inputenc}                         
\usepackage[lf, p, sflf, sfp]{libertine}
\usepackage{biblatex}

\KOMAoptions{%
    listof=totoc,                                       
    bibliography=totoc                                  
}
\makeatletter                               
\def\thickhrulefill{\leavevmode \leaders \hrule height 1ex \hfill \kern \z@}
\def\@makechapterhead#1{%
    \vspace*{10\p@}%
    {\parindent \z@ \centering \reset@font
        \thickhrulefill\quad
        \scshape \@chapapp{} \thechapter
        \quad \thickhrulefill
        \par\nobreak
        \vspace*{10\p@}%
        \interlinepenalty\@M
        \hrule
        \vspace*{10\p@}%
        \Huge \bfseries #1\par\nobreak
        \par
        \vspace*{10\p@}%
        \hrule
        \vskip 100\p@
}}
    \def\@makeschapterhead#1{%
    \vspace*{10\p@}%
    {\parindent \z@ \centering \reset@font
        \thickhrulefill
        \par\nobreak
        \vspace*{10\p@}%
        \interlinepenalty\@M
        \hrule
        \vspace*{10\p@}%
        \Huge \bfseries #1\par\nobreak
        \par
        \vspace*{10\p@}%
        \hrule
        \vskip 100\p@
}}

\begin{document}
    \addchap{Abbr.}
    \tableofcontents
    \chapter{Ch 1}  
    \chapter{Ch 2}
    \printbibliography
    \begin{thebibliography}{99}
        \bibitem{mmax} Max Power: \emph{Power of Max}. Hard Power.
    \end{thebibliography}
    \appendix   
    \addchap{App}
\end{document}

答案1

使用 KOMA-Script 类,不建议重新定义内部命令。

以下是重新定义记录的宏的建议\chapterlinesformat

\documentclass[
  %paper=a4, pagesize=auto,% default
  fontsize = 12pt
]{scrbook}
%\providecommand*\Ifstr{\ifstr}% needed up to and including KOMA-Script version 3.27, see https://komascript.de/faq_deprecatedif
\usepackage[T1]{fontenc}
%\usepackage[utf8]{inputenc}% needed for older TeX distributions
\usepackage[lf, p, sflf, sfp]{libertine}
%\usepackage{biblatex}

\KOMAoptions{%
    listof=totoc,
    bibliography=totoc
}

\RedeclareSectionCommand[
  beforeskip=\dimexpr10pt+\baselineskip\relax,
  afterskip=100pt,
  afterindent=false,
  font=\normalfont\normalsize,
]{chapter}
\newkomafont{chapterprefixline}{\scshape}
\newkomafont{chaptertitle}{\Huge\bfseries}
\renewcommand\raggedchapter{\centering}
\renewcommand\chapterformat{%
  \usekomafont{chapterprefixline}%
  \thickhrulefill\quad\mbox{\chapapp\nobreakspace\thechapter}\quad\thickhrulefill
}


\makeatletter
\def\thickhrulefill{\leavevmode \leaders \hrule height 1ex \hfill \kern \z@}
\renewcommand\chapterlinesformat[3]{%
  \Ifstr{#1}{chapter}
    {%
      \IfArgIsEmpty{#2}{\thickhrulefill}{#2}%
      \par\nobreak
      \vspace*{10\p@}%
      \interlinepenalty\@M
      \hrule
      \vspace*{10\p@}%
      \usekomafont{chaptertitle}#3\par\nobreak
      \par
      \vspace*{10\p@}%
      \hrule
    }
    {#2#3}%
}

\begin{document}
\addchap{Abbr.}
\tableofcontents
\chapter{Ch 1}
\chapter{Ch 2}
%\printbibliography
\begin{thebibliography}{99}
  \bibitem{mmax} Max Power: \emph{Power of Max}. Hard Power.
\end{thebibliography}
\appendix
\addchap{App}
\end{document}

结果:

在此处输入图片描述

答案2

您可以测试 secnumdepth 的当前值:

\documentclass[paper=a4, pagesize=auto, fontsize = 12pt]{scrbook}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[lf, p, sflf, sfp]{libertine}
\usepackage{biblatex}

\KOMAoptions{%
    listof=totoc,
    bibliography=totoc
}
\makeatletter
\def\thickhrulefill{\leavevmode \leaders \hrule height 1ex \hfill \kern \z@}
\def\@makechapterhead#1{%
    \vspace*{10\p@}%
    {\parindent \z@ \centering \reset@font
        \ifnum \c@secnumdepth < \chapternumdepth\relax
         \thickhrulefill
        \else 
         \thickhrulefill\quad
         \scshape \@chapapp{} \thechapter
         \quad \thickhrulefill
        \fi
        \par\nobreak
        \vspace*{10\p@}%
        \interlinepenalty\@M
        \hrule
        \vspace*{10\p@}%
        \Huge \bfseries #1\par\nobreak
        \par
        \vspace*{10\p@}%
        \hrule
        \vskip 100\p@
}}
    \def\@makeschapterhead#1{%
    \vspace*{10\p@}%
    {\parindent \z@ \centering \reset@font
        \thickhrulefill
        \par\nobreak
        \vspace*{10\p@}%
        \interlinepenalty\@M
        \hrule
        \vspace*{10\p@}%
        \Huge \bfseries #1\par\nobreak
        \par
        \vspace*{10\p@}%
        \hrule
        \vskip 100\p@
}}

\begin{document}
    \addchap{Abbr.}
    \tableofcontents
    \chapter{Ch 1}
    \chapter{Ch 2}
    \printbibliography
    \begin{thebibliography}{99}
        \bibitem{mmax} Max Power: \emph{Power of Max}. Hard Power.
    \end{thebibliography}
    \appendix
    \addchap{App}
\end{document}

相关内容