在 scrbook 类中使用 TiKZ 装饰“目录”和“列表”页面

在 scrbook 类中使用 TiKZ 装饰“目录”和“列表”页面

我正在使用该类scrbook编写文档,因为它具有很高的灵活性。问题是,当我尝试自定义章节时,我成功地仅更改了章节mainmatter,但对于\tableofcontents\listoffigures和,\listoftables我无法执行相同的操作。我需要在这些项目的标题下添加一个简单的规则,如下图所示:

在此处输入图片描述

我发现的大多数答案都依赖于titlesec软件包,但软件包与 并不完全兼容,KOMA script并且会影响所有已经定制好的章节。我喜欢使用它,TiKZ因为它功能强大且质量高。目前,我用它\renewcommand*{\chapterformat}来定制我的章节。有没有人知道如何对页面进行此操作\frontmatter?谢谢。

\documentclass[fontsize=12pt,
               twoside=false,%
               toc=listof,%
               toc=bibliography,%
               chapterprefix=true,%
               captions=tableheading,%
               numbers=noenddot]{scrbook}
\usepackage[T1]{fontenc}
\usepackage{newtxtext,newtxmath}
\usepackage{amsmath}
\usepackage{setspace}
\usepackage{tikz,calc}  
\usetikzlibrary{calc,decorations.pathreplacing}
\usepackage[titletoc]{appendix}

\addtokomafont{sectioning}{\rmfamily}
\addtokomafont{chapter}{\raggedleft\linespread{1}}
\usepackage[headsepline]{scrpage2}

\renewcommand*{\chapterformat}{\normalfont%
              {\fontsize{20}{30}\scshape\chapappifchapterprefix{}}
              {\fontsize{80}{30}\selectfont\thechapter}%
              \tikz{\coordinate(h);
              \draw[overlay,remember picture,line width=1.5pt]%
              ([yshift=-07pt]h)--++(-150mm,0)%
}}%

\renewcommand{\contentsname}{Table of Contents}

\begin{document}
\frontmatter
\setstretch{1.62}
\pagestyle{plain}
\chapter{Dedication}        %====== Dedication
\chapter{Acknowledgments}   %====== Acknowledgments
\chapter{Abstract}          %====== Abstract
\tableofcontents            %====== Table of Contents
\listoffigures              %====== List of Figures
\listoftables               %====== List of Tables
\chapter{Abbreviations}     %====== List of Abbreviations
\mainmatter
\chapter{Chapter1}  
\chapter{Chapter2}  
\chapter{Chapter3}      
\appendix
\chapter{Appendix A}    
\backmatter
\chapter{References}
\end{document}

答案1

您可以加载etoolbox并更改\chapterheadendvskip为在主要内容之外的章节标题中插入该行:

\usepackage{etoolbox}
\makeatletter
\preto{\chapterheadendvskip}{%
  \if@mainmatter\else% only outside mainmatter
    \vspace{-\baselineskip}\hfill%
    \tikz{\coordinate(h);%
      \draw[overlay,remember picture,line width=1.5pt]%
        ([yshift=-7pt]h)--++(-150mm,0);}%
    \par\fi%
}
\makeatother

在此处输入图片描述

代码:

请注意,该软件包scrpage2已过时。后继版本是scrlayer-scrpage

\documentclass[fontsize=12pt,
               twoside=false,%
               toc=listof,%
               toc=bibliography,%
               chapterprefix=true,%
               captions=tableheading,%
               numbers=noenddot]{scrbook}
\usepackage[T1]{fontenc}
\usepackage{newtxtext,newtxmath}
\usepackage{amsmath}
\usepackage{setspace}
\usepackage{calc}
\usepackage{tikz}
\usetikzlibrary{calc,decorations.pathreplacing}
\usepackage[titletoc]{appendix}

\addtokomafont{sectioning}{\rmfamily}
\addtokomafont{chapter}{\linespread{1}}
\renewcommand\raggedchapter{\raggedleft}
\usepackage[headsepline]{scrlayer-scrpage}
\KOMAoptions{onpsinit=\linespread{1}}

\renewcommand*{\chapterformat}{\normalfont%
              {\fontsize{20}{30}\scshape\chapappifchapterprefix{}}
              {\fontsize{80}{30}\selectfont\thechapter}%
              \tikz{\coordinate(h);
              \draw[overlay,line width=1.5pt]%
              ([yshift=-7pt]h)--++(-150mm,0);%
}}%

\usepackage{etoolbox}
\makeatletter
\preto{\chapterheadendvskip}{%
  \if@mainmatter\else% only outside mainmatter
    \vspace{-\baselineskip}\hfill%
    \tikz{\coordinate(h);%
      \draw[overlay,remember picture,line width=1.5pt]%
        ([yshift=-7pt]h)--++(-150mm,0);}%
    \par\fi%
}
\makeatother

\usepackage[english]{babel}
\renewcaptionname{english}{\contentsname}{Table of Contents}

\usepackage{blindtext}% dummy text
%\usepackage{showframe}% to show the page layout

\begin{document}
\frontmatter
\pagestyle{plain}
\setstretch{1.62}
\chapter{Dedication}        %====== Dedication
\textbf{\KOMAScriptVersion}

\blindtext
\chapter{Acknowledgments}   %====== Acknowledgments
\blindtext
\chapter{Abstract}          %====== Abstract
\blindtext
\tableofcontents            %====== Table of Contents
%\listoffigures              %====== List of Figures
%\listoftables               %====== List of Tables
%\chapter{Abbreviations}     %====== List of Abbreviations
\mainmatter
\pagestyle{scrheadings}
\blinddocument
\appendix
\blinddocument
\backmatter
\chapter{References}
\blindtext
\end{document}

您还可以按照评论中的要求将主要内容之外的章节左对齐。使用

\makeatother
\renewcommand\raggedchapter{\if@mainmatter\raggedleft\else\fi}
\makeatother

或者

\makeatother
\renewcommand\raggedchapter{\if@mainmatter\raggedleft\else\raggedright\fi}
\makeatother

但是本章标题下的规则也应该左对齐:

\usepackage{etoolbox}
\makeatletter
\preto{\chapterheadendvskip}{%
  \if@mainmatter\else% only outside mainmatter
    \vspace{-\baselineskip}\noindent%
    \tikz{\coordinate(h);%
      \draw[overlay,remember picture,line width=1.5pt]%
        ([yshift=-7pt]h)--++(150mm,0);}%
    \par\fi%
}
\makeatother

在此处输入图片描述

代码:

\documentclass[fontsize=12pt,
               twoside=false,%
               toc=listof,%
               toc=bibliography,%
               chapterprefix=true,%
               captions=tableheading,%
               numbers=noenddot]{scrbook}
\usepackage[T1]{fontenc}
\usepackage{newtxtext,newtxmath}
\usepackage{amsmath}
\usepackage{setspace}
\usepackage{calc}
\usepackage{tikz}
\usetikzlibrary{calc,decorations.pathreplacing}
\usepackage[titletoc]{appendix}

\addtokomafont{sectioning}{\rmfamily}
\addtokomafont{chapter}{\linespread{1}}

\usepackage[headsepline]{scrlayer-scrpage}
\KOMAoptions{onpsinit=\linespread{1}}

\renewcommand*{\chapterformat}{\normalfont%
              {\fontsize{20}{30}\scshape\chapappifchapterprefix{}}
              {\fontsize{80}{30}\selectfont\thechapter}%
              \tikz{\coordinate(h);
              \draw[overlay,line width=1.5pt]%
              ([yshift=-7pt]h)--++(-150mm,0);%
}}%

\usepackage{etoolbox}
\makeatletter
\preto{\chapterheadendvskip}{%
  \if@mainmatter\else% only outside mainmatter
    \vspace{-\baselineskip}\noindent%
    \tikz{\coordinate(h);%
      \draw[overlay,remember picture,line width=1.5pt]%
        ([yshift=-7pt]h)--++(150mm,0);}%
    \par\fi%
}
\renewcommand\raggedchapter{\if@mainmatter\raggedleft\else\fi}
\makeatother

\usepackage[english]{babel}
\renewcaptionname{english}{\contentsname}{Table of Contents}

\usepackage{blindtext}% dummy text
%\usepackage{showframe}% to show the page layout

\begin{document}
\frontmatter
\pagestyle{plain}
\setstretch{1.62}
\chapter{Dedication}        %====== Dedication
\textbf{\KOMAScriptVersion}

\blindtext
\chapter{Acknowledgments}   %====== Acknowledgments
\blindtext
\chapter{Abstract}          %====== Abstract
\blindtext
\tableofcontents            %====== Table of Contents
%\listoffigures              %====== List of Figures
%\listoftables               %====== List of Tables
%\chapter{Abbreviations}     %====== List of Abbreviations
\mainmatter
\pagestyle{scrheadings}
\blinddocument
\appendix
\blinddocument
\backmatter
\chapter{References}
\blindtext
\end{document}

相关内容