![修改未编号部分](https://linux22.com/image/375331/%E4%BF%AE%E6%94%B9%E6%9C%AA%E7%BC%96%E5%8F%B7%E9%83%A8%E5%88%86.png)
此代码来自这里做了一点修改。我只\part*{Unnumbered Part}
在底部添加了。
\documentclass{scrbook}
\usepackage[Bjornstrup]{fncychap}
\usepackage{xcolor}
\colorlet{partbgcolor}{gray!30}% shaded background color for parts
\colorlet{partnumcolor}{gray}% color for numbers in parts
\colorlet{chapbgcolor}{gray!30}% shaded background color for chapters
\colorlet{chapnumcolor}{gray}% color for numbers in chapters
\renewcommand*\partformat{%
\fontsize{76}{80}\usefont{T1}{pzc}{m}{n}\selectfont%
\hfill\textcolor{partnumcolor}{\thepart}}
\makeatletter
\renewcommand*{\@part}{}
\def\@part[#1]#2{%
\ifnum \c@secnumdepth >-2\relax
\refstepcounter{part}%
\@maybeautodot\thepart%
\addparttocentry{\thepart}{#1}%
\else
\addparttocentry{}{#1}%
\fi
\begingroup
\setparsizes{\z@}{\z@}{\z@\@plus 1fil}\par@updaterelative
\raggedpart
\interlinepenalty \@M
\normalfont\sectfont\nobreak
\setlength\fboxsep{0pt}
\colorbox{partbgcolor}{\rule{0pt}{40pt}%
\makebox[\linewidth]{%
\begin{minipage}{\dimexpr\linewidth+20pt\relax}
\ifnum \c@secnumdepth >-2\relax
\vskip-25pt
\size@partnumber{\partformat}%
\fi %
\vskip\baselineskip
\hspace*{\dimexpr\myhi+10pt\relax}%
\parbox{\dimexpr\linewidth-2\myhi-20pt\relax}{\raggedleft\LARGE#2\strut}%
\hspace*{\myhi}\par\medskip%
\end{minipage}%
}%
}%
\partmark{#1}\par
\endgroup
\@endpart
}
\renewcommand\DOCH{%
\settowidth{\py}{\CNoV\thechapter}
\addtolength{\py}{-10pt}
\fboxsep=0pt%
\colorbox{chapbgcolor}{\rule{0pt}{40pt}\parbox[b]{\textwidth}{\hfill}}%
\kern-\py\raise20pt%
\hbox{\color{chapnumcolor}\CNoV\thechapter}\\%
}
\renewcommand\DOTI[1]{%
\nointerlineskip\raggedright%
\fboxsep=\myhi%
\vskip-1ex%
\colorbox{chapbgcolor}{\parbox[t]{\mylen}{\CTV\FmTi{#1}}}\par\nobreak%
\vskip 40pt%
}
\renewcommand\DOTIS[1]{%
\fboxsep=0pt
\colorbox{chapbgcolor}{\rule{0pt}{40pt}\parbox[b]{\textwidth}{\hfill}}\\%
\nointerlineskip\raggedright%
\fboxsep=\myhi%
\colorbox{chapbgcolor}{\parbox[t]{\mylen}{\CTV\FmTi{#1}}}\par\nobreak%
\vskip 40pt%
}
\makeatother
\begin{document}
\part{Test Part}
\chapter{Test Chapter}
\part*{Unnumbered Part}
\end{document}
如何使自定义零件样式也适用于未编号的零件(当然没有零件编号)?
答案1
\chapterlineswithprefixformat
以下是重新定义和 的建议\partlineswithprefixformat
。第二个宏(关于部分)是在 KOMA-Script 版本 3.25 中引入的。因此,您至少需要此版本才能运行以下代码:
\documentclass{scrbook}[2018/03/30]% needs at least KOMA-Script version 3.25
\usepackage{xcolor}
\colorlet{partbgcolor}{gray!30}% shaded background color for parts
\colorlet{partnumcolor}{gray}% color for numbers in parts
\colorlet{chapbgcolor}{gray!30}% shaded background color for chapters
\colorlet{chapnumcolor}{gray}% color for numbers in chapters
\newlength{\myhi}
\setlength\myhi{10pt}
\renewcommand\raggedpart{\raggedleft}
\setkomafont{part}{\Large}
\RedeclareSectionCommand[innerskip=0pt]{part}
\renewcommand*\partformat{%
\fontsize{76}{80}\usefont{T1}{pzc}{m}{n}\selectfont%
\makebox[0pt][l]{\makebox[\myhi][r]{\textcolor{partnumcolor}{\thepart}}}}
\renewcommand\raggedchapter{\raggedleft}
\setkomafont{chapter}{\Large}
\RedeclareSectionCommand[innerskip=0pt]{chapter}
\renewcommand*\chapterformat{%
\fontsize{76}{80}\usefont{T1}{pzc}{m}{n}\selectfont%
\makebox[0pt][l]{\makebox[\myhi][r]{\textcolor{chapnumcolor}{\thechapter}}}}
\renewcommand\partlineswithprefixformat[3]{% needs at least KOMA-Script version 3.25
\ifstr{#1}{part}
{%
\raggedpart
\setlength\fboxsep{0pt}%
\colorbox{partbgcolor}{\rule{0pt}{20pt}%
\hspace*{\myhi}%
\begin{minipage}[t]{\dimexpr\linewidth-2\myhi\relax}
\vskip\baselineskip
\raggedpart#3\strut
\vspace*{\dimexpr-\baselineskip+\myhi\relax}%
\end{minipage}%
\hspace*{\myhi}%
}%
#2\par
}
{#2#3}% default code for other section levels with style=part
}
\renewcommand\chapterlinesformat[3]{%
\ifstr{#1}{chapter}
{%
\raggedchapter
\setlength\fboxsep{0pt}%
\colorbox{chapbgcolor}{\rule{0pt}{20pt}%
\hspace*{\myhi}%
\begin{minipage}[t]{\dimexpr\linewidth-2\myhi\relax}
\vskip\baselineskip
\raggedchapter#3\strut
\vspace*{\dimexpr-\baselineskip+\myhi\relax}\par
\end{minipage}%
\hspace*{\myhi}%
}%
#2\par
}
{#2#3}% default code for other section levels with style=chapter
}
\usepackage{blindtext}% only for dummy text
\begin{document}
\tableofcontents
\part{Test Part}
\chapter{Test Chapter}
\blindtext
\KOMAScriptVersion
\part{Next Part}
\blinddocument
\addpart*{Unnumbered Part}
\end{document}