scrlayer-scrpage:更改标题中的文本字体

scrlayer-scrpage:更改标题中的文本字体

我用scrreprt它来做课堂笔记,并根据自己的喜好更改了页面布局。但是首先我想更改页眉的字体以\mdseries匹配章节前缀。

我也使用该选项headsepline,但想删除“章节前缀”和“章节名称”之间的线。

任何帮助,将不胜感激。

梅威瑟:

\documentclass[
    numbers=endperiod,
    toc=chapterentrydotfill,
    DIV=12
    ]
    {scrreprt}
    
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{csquotes}
\usepackage{lmodern}
\usepackage{microtype}
\usepackage[
  automark,
  autooneside=false,
  headsepline=true
    ]
    {scrlayer-scrpage}
    \pagestyle{scrheadings}
    \cohead{\Ifthispageodd{\rightmark}{\leftmark}}
    \cfoot*{\pagemark}
\usepackage{textcomp}

\let\raggedchapter\centering

\setkomafont{chapterprefix}{\normalsize\mdseries}
\KOMAoption{chapterprefix}{true}

\renewcommand{\chapterheadmidvskip}{%
    \par\nobreak\vskip -.1cm {\rule{\textwidth}{.5pt}}\par%
}
\RedeclareSectionCommand[beforeskip=0pt,afterskip=15pt]{chapter}
\usepackage{xpatch}
\tracingpatches
\xpatchcmd{\@@makeschapterhead}{%for the unnumbered
    \usekomafont{chapter}{#1}\par
}{%
    \usekomafont{chapter}{\MakeUppercase{#1}}\par
}{}{}
\xpatchcmd{\@@makechapterhead}{%for numbered
    \usekomafont{chapter}{#1}\par
}{%
    \usekomafont{chapter}{\MakeUppercase{#1}}\par
}{}{}
\renewcommand*{\chapterformat}{%
    \mbox{\huge\MakeUppercase{\chapappifchapterprefix{\nobreakspace}}\thechapter\autodot
    \IfUsePrefixLine{}{\enskip}}%
}

\renewcommand{\abstract}[1]{%
    \textbf{Abstract.} #1\par%
}

\usepackage{lipsum}


\begin{document}
    \tableofcontents
    \thispagestyle{empty}
    \setcounter{page}{0}
    
    \chapter{The Chapter Numbered One}
        \abstract{\lipsum[3]}
        
        \section{The Section Which Comes First}
            \lipsum
            
            \subsection{First Subsection}
                \lipsum
        
\end{document}

答案1

如果章节前缀和章节名称之间不应该有一行,请删除 的重新定义\chapterheadmidvskip。(题外话:\chapterheadmidvskip不应该用来插入这样的一行。)章节前缀和章节名称之间的垂直间距可以通过选项 进行调整innerskip,例如:

\RedeclareSectionCommand[beforeskip=0pt,afterskip=15pt,innerskip=7.5pt]{chapter}

如果章节前缀和章节名称应该大写,则重新定义\chapterlineswithprefixformat

\renewcommand*{\chapterlineswithprefixformat}[3]{%
  \Ifstr{#1}{chapter}
    {\MakeUppercase{#2#3}}
    {#2#3}%
}

如果章节前缀应该\huge使用

\setkomafont{chapterprefix}{\mdseries\huge}

如果页眉应该是向上的,则使用\addtokomafont{pagehead}{\upshape}\addtokomafont{pageheadfoot}{\upshape}

\documentclass[
  numbers=endperiod,
  toc=chapterentrydotfill,
  DIV=12
]{scrreprt}
\usepackage{lipsum}% only for dummy text

\usepackage[T1]{fontenc}
%\usepackage[utf8]{inputenc}% only needed with outdated TeX distributions
\usepackage{csquotes}
\usepackage{lmodern}
\usepackage{microtype}
\usepackage{textcomp}

\usepackage[
  automark,
  autooneside=false,
  headsepline=true
]{scrlayer-scrpage}% sets page style scrheadinges automatically
\clearpairofpagestyles
\chead{\ifodd\value{page}\rightmark\else\leftmark\fi}
\cfoot*{\pagemark}
\addtokomafont{pageheadfoot}{\upshape}

\let\raggedchapter\centering
\setkomafont{chapterprefix}{\mdseries\huge}
\KOMAoption{chapterprefix}{true}

\RedeclareSectionCommand[beforeskip=0pt,afterskip=15pt,innerskip=7.5pt]{chapter}
\renewcommand*{\chapterlineswithprefixformat}[3]{%
  \Ifstr{#1}{chapter}
    {\MakeUppercase{#2#3}}
    {#2#3}%
}

\renewcommand{\abstract}[1]{%
    \textbf{Abstract.} #1\par%
}

\BeforeStartingTOC[toc]{\thispagestyle{empty}\pagestyle{empty}}
\AfterStartingTOC[toc]{\clearpage}

\begin{document}
\pagenumbering{roman}
\tableofcontents

\cleardoubleoddpage
\pagenumbering{arabic}
\chapter{The Chapter Numbered One}
\abstract{\lipsum[3]}

\section{The Section Which Comes First}
\lipsum
\subsection{First Subsection}
\lipsum
\end{document}

在此处输入图片描述

相关内容