我正在尝试自定义文档不同内容中的章节格式。如何从前言部分获取章节标题下的蓝色条?这是我迄今为止获得的最好的结果...
注意:如果您没有 arial 字体,请用任何字体替换,以便运行示例。
\documentclass[
a4paper,
oneside,
11pt,
cleardoublepage=empty,
numbers=noenddot,
titlepage,
toc=bibliography,
chapterprefix=true,
headings=chapterprefix,
toc=index,
]{scrbook}
\usepackage{textcase}
% fonts
\RequirePackage{fontspec}
%\newfontfamily\AdobeCaslonPro{Adobe Caslon Pro}
%\newfontfamily\ZapfHumnstBT{ZapfHumnst BT}
%\newfontfamily\ZapfHumnstDmBT{ZapfHumnst Dm BT}
%\newfontfamily\ZapfHumnstUltBT{ZapfHumnst Ult BT}
\newfontfamily\AdobeCaslonPro{arial}
\newfontfamily\ZapfHumnstBT{arial}
\newfontfamily\ZapfHumnstDmBT{arial}
\newfontfamily\ZapfHumnstUltBT{arial}
% colors
\RequirePackage[usenames,dvipsnames]{xcolor}
\definecolor{darkbluejebrack}{RGB}{0,141,198}
\definecolor{mediumbluejebrack}{RGB}{0,171,238}
\definecolor{lightbluejebrack}{RGB}{114,214,247}
\newcommand{\titleprefixfontsize}{\fontsize{30}{30}}
\newcommand{\titlefontsize}{\fontsize{20}{20}}
\newcommand\titlerule[1][1pt]{\rule{\textwidth}{#1}}
\newcommand{\titlesubbar}{{\color{lightbluejebrack} \rule[.4\baselineskip]{\linewidth}{1.2mm}}}
%% This is for the spacing around chapter (above and under)
\RedeclareSectionCommand[innerskip=0pt]{chapter}
\makeatletter
\newcommand\matter@switch{}
\addtokomafont{chapterentry}{\matter@switch}
\g@addto@macro\frontmatter{%
\addtocontents{toc}{%
\protect\renewcommand\protect\matter@switch{\normalfont\itshape}%
}%
\setkomafont{chapter}{\titleprefixfontsize \normalfont \bfseries \ZapfHumnstDmBT \MakeTextUppercase}%
}
\g@addto@macro\mainmatter{%
\addtocontents{toc}{%
\protect\renewcommand\protect\matter@switch{}%
}%
\setkomafont{chapter}{\titlefontsize \AdobeCaslonPro \bfseries}%
\setkomafont{chapterprefix}{\titleprefixfontsize \normalfont \bfseries \ZapfHumnstDmBT
\MakeTextUppercase}
% Add a blue line under "CHAPTER"
\renewcommand\chapterlineswithprefixformat[3]{%
#2\nobreak\vspace{-.15cm}%
\titlesubbar\par\nobreak%%
\Ifstr{#2}{}{}{\kern-\dp\strutbox}
#3%
}
}
\begin{document}
\frontmatter
\tableofcontents
\chapter{Preface}
\chapter{Acknowledgements}
\mainmatter
\chapter{First Chapter}
\chapter{Second Chapter}
\end{document}
答案1
您还可以将您的内容添加到插件内的\titlesubbar
重新定义中:\chapterlineswithprefixformat
\frontmatter
\documentclass[
a4paper,
oneside,
11pt,
cleardoublepage=empty,
numbers=noenddot,
titlepage,
toc=bibliography,
chapterprefix=true,
headings=chapterprefix,
toc=index,
]{scrbook}
\usepackage{textcase}
% colors
\RequirePackage[usenames,dvipsnames]{xcolor}
\definecolor{darkbluejebrack}{RGB}{0,141,198}
\definecolor{mediumbluejebrack}{RGB}{0,171,238}
\definecolor{lightbluejebrack}{RGB}{114,214,247}
\newcommand{\titleprefixfontsize}{\fontsize{30}{30}}
\newcommand{\titlefontsize}{\fontsize{20}{20}}
\newcommand\titlerule[1][1pt]{\rule{\textwidth}{#1}}
\DeclareRobustCommand{\titlesubbar}{{\color{lightbluejebrack} \rule[.4\baselineskip]{\linewidth}{1.2mm}}}
%% This is for the spacing around chapter (above and under)
\RedeclareSectionCommand[innerskip=0pt]{chapter}
\makeatletter
\newcommand\matter@switch{}
\addtokomafont{chapterentry}{\matter@switch}
\g@addto@macro\frontmatter{%
\addtocontents{toc}{%
\protect\renewcommand\protect\matter@switch{\normalfont\itshape}%
}%
\setkomafont{chapter}{\titleprefixfontsize \normalfont \bfseries \MakeTextUppercase}%
\renewcommand\chapterlineswithprefixformat[3]{%
{#2#3}% original definition
\IfArgIsEmpty{#2}{\vskip-\dp\strutbox\titlesubbar\par\nobreak}{}% added
}
}
\g@addto@macro\mainmatter{%
\addtocontents{toc}{%
\protect\renewcommand\protect\matter@switch{}%
}%
\setkomafont{chapter}{\titlefontsize \bfseries}%
\setkomafont{chapterprefix}{\titleprefixfontsize \normalfont \bfseries
\MakeTextUppercase}
% Add a blue line under "CHAPTER"
\renewcommand\chapterlineswithprefixformat[3]{%
#2\nobreak\vspace{-.15cm}%
\titlesubbar\par\nobreak%%
\Ifstr{#2}{}{}{\kern-\dp\strutbox}
#3%
}
}
\makeatother
\begin{document}
\frontmatter
\tableofcontents
\chapter{Preface}
\chapter{Acknowledgements}
\mainmatter
\chapter{First Chapter}
\chapter{Second Chapter}
\end{document}
注意:我已删除字体,以使示例编译独立于操作系统和已安装的字体,并独立于 TeX 引擎。
还请注意:由于\MakeTextUppercase
不是字体命令,在的第二个参数中使用\setkomafont
或\addtokomafont
它超出了规范,因此很危险。恕我直言,最好将其移到的重新定义中\chapterlineswidthprefixformat
:
\documentclass[
a4paper,
oneside,
11pt,
cleardoublepage=empty,
numbers=noenddot,
titlepage,
toc=bibliography,
chapterprefix=true,
headings=chapterprefix,
toc=index,
]{scrbook}
\usepackage{textcase}
% colors
\RequirePackage[usenames,dvipsnames]{xcolor}
\definecolor{darkbluejebrack}{RGB}{0,141,198}
\definecolor{mediumbluejebrack}{RGB}{0,171,238}
\definecolor{lightbluejebrack}{RGB}{114,214,247}
\newcommand{\titleprefixfontsize}{\fontsize{30}{30}\selectfont}
\newcommand{\titlefontsize}{\fontsize{20}{20}\selectfont}
\newcommand\titlerule[1][1pt]{\rule{\textwidth}{#1}}
\DeclareRobustCommand{\titlesubbar}{{\color{lightbluejebrack} \rule[.4\baselineskip]{\linewidth}{1.2mm}}}
%% This is for the spacing around chapter (above and under)
\RedeclareSectionCommand[innerskip=0pt]{chapter}
\makeatletter
\newcommand\matter@switch{}
\addtokomafont{chapterentry}{\matter@switch}
\setkomafont{chapterprefix}{\titleprefixfontsize \normalfont \bfseries}
\g@addto@macro\frontmatter{%
\addtocontents{toc}{%
\protect\renewcommand\protect\matter@switch{\normalfont\itshape}%
}%
\setkomafont{chapter}{\usekomafont{chapterprefix}}%
}
\g@addto@macro\mainmatter{%
\addtocontents{toc}{%
\protect\renewcommand\protect\matter@switch{}%
}%
\setkomafont{chapter}{\titlefontsize \bfseries}%
}
% Add a blue line under "CHAPTER" resp. under the title
\renewcommand\chapterlineswithprefixformat[3]{%
\MakeTextUppercase{#2}%
\if@mainmatter
\nobreak% shouldn't be needed here
\vspace{-.15cm}%
\titlesubbar\par
\nobreak% shouldn't be needed here
#3%
\else
\MakeTextUppercase{#3}%
\IfArgIsEmpty{#2}{\vskip-\dp\strutbox\titlesubbar\par\nobreak}{}%
\fi
}
\makeatother
\begin{document}
\frontmatter
\tableofcontents
\chapter{Preface}
\chapter{Acknowledgements}
\mainmatter
\chapter{First Chapter}
\chapter{Second Chapter}
\end{document}
关于的注释\nobreak
在这里,因为\chapter
应该总是从新页面开始,因此在章节标题中不应该出现分页符。如果需要,那么无论有没有,你都会遇到麻烦\nobreak
。;-)