KOMA:章节和标题样式(大写 + Chapterprexif)

KOMA:章节和标题样式(大写 + Chapterprexif)

KOMA-Script 中是否有方法(或解决方法/包)将章节名称放在大写以及章节前缀小写字母并且下一页的页眉没有前缀,如下图所示?

期望输出: enter image description here

目前我得到了以下信息:

\documentclass[
     paper = a4,
     twoside = false,
     numbers = noenddot,  
     parskip = half,
     listof = flat,
     listof = entryprefix,
     chapterprefix = true,
     listof = nochaptergap]{scrreprt}

\renewcommand*{\chapterformat}{%Chapter name indentation
  \makebox[1.15cm][l]{\thechapter\autodot}%
}
\makeatletter %Uppercase chapter name
\renewcommand\chapterlinesformat[3]{%
  \@hangfrom{#2}{\MakeUppercase{#3}}%
}
\makeatother
\renewcommand*{\sectionformat}{%
  \makebox[1.15cm][l]{\thesection\autodot}%
}
\renewcommand*{\subsectionformat}{%
  \makebox[1.15cm][l]{\thesubsection\autodot}%
}  

% ============================================
% HEADER & FOOTER
% ============================================
\usepackage[automark]{scrlayer-scrpage}
     \clearpairofpagestyles
     \ohead{\MakeUppercase{\headmark}} %Chapter name in header
     \ofoot*{\pagemark} %Page number
     \setkomafont{pagehead}{\sffamily\bfseries\upshape}
     \setkomafont{pagenumber}{\sffamily\bfseries\upshape}

\begin{document}
\chapter{Introduction}
\section{Section}
\newpage
Lorem ipsum
\end{document}

答案1

您已设置选项chapterprefix=true,因此必须重新定义\chapterlineswithprefixformat

\renewcommand*\chapterlineswithprefixformat[3]{%
  \ifstr{#1}{chapter}
    {#2\MakeUppercase{#3}}% changed definition for chapter
    {#2#3}% original definition for other levels with style=chapter
}

为了使章节标题右对齐,请重新定义\raggedchapter\raggedleft

\renewcommand*\raggedchapter{\raggedleft}% <- chapter alignment

\chaptermarkformat可以简单地重新定义以删除章节名称:

\renewcommand*\chaptermarkformat{\thechapter\autodot\enskip}% for header

请注意,有一个选项markcase=upper可以将左标记和右标记设置为大写:

\usepackage[
  automark,
  markcase=upper% <- uppercase for left and right marks
]{scrlayer-scrpage}
\ohead{\headmark}% <- changed

例子:

\documentclass[
  paper = a4,
  twoside = false,
  numbers = noenddot,  
  parskip = half,
  listof = flat,
  listof = entryprefix,
  chapterprefix = true,
  listof = nochaptergap
]{scrreprt}
\usepackage[T1]{fontenc}% <- added

\RedeclareSectionCommand[
  innerskip=0pt,% skip between chapter prefix and chapter title
  prefixfont=\LARGE% font of chapter prefix
]{chapter}
\renewcommand*\raggedchapter{\raggedleft}% <- chapter alignment
\renewcommand*\chapterlineswithprefixformat[3]{%
  \ifstr{#1}{chapter}
    {#2\MakeUppercase{#3}}% changed definition for chapter
    {#2#3}% original definition for other levels with style=chapter
}
\renewcommand*\chaptermarkformat{\thechapter\autodot\enskip}% for header

\renewcommand*{\sectionformat}{%
  \makebox[1.15cm][l]{\thesection\autodot}%
}
\renewcommand*{\subsectionformat}{%
  \makebox[1.15cm][l]{\thesubsection\autodot}%
}  

% ============================================
% HEADER & FOOTER
% ============================================
\usepackage[
  automark,
  markcase=upper% <- uppercase for left and right marks
]{scrlayer-scrpage}
\clearpairofpagestyles
\ohead{\headmark}% <- changed
\ofoot*{\pagemark}
\setkomafont{pagehead}{\sffamily\bfseries\upshape}
\addtokomafont{pagenumber}{\sffamily\bfseries}

\begin{document}
\chapter{Introduction}
\section{Section}
\newpage
Lorem ipsum
\end{document}

结果:

enter image description here

或者使用\textls*包提供的包microtype

enter image description here

代码:

\documentclass[
  paper = a4,
  twoside = false,
  numbers = noenddot,  
  parskip = half,
  listof = flat,
  listof = entryprefix,
  chapterprefix = true,
  listof = nochaptergap
]{scrreprt}
\usepackage[T1]{fontenc}% <- added
\usepackage{microtype}% <- added

\RedeclareSectionCommand[
  innerskip=0pt,% skip between chapter prefix and chapter title
  prefixfont=\LARGE% font of chapter prefix
]{chapter}
\renewcommand*\raggedchapter{\raggedleft}% <- chapter alignment
\renewcommand*\chapterlineswithprefixformat[3]{%
  \ifstr{#1}{chapter}
    {#2\textls*[75]{\MakeUppercase{#3}}}% changed definition for chapter
    {#2#3}% original definition
}
\renewcommand*\chaptermarkformat{\thechapter\autodot\enskip}% for header

\renewcommand*{\sectionformat}{%
  \makebox[1.15cm][l]{\thesection\autodot}%
}
\renewcommand*{\subsectionformat}{%
  \makebox[1.15cm][l]{\thesubsection\autodot}%
}  

% ============================================
% HEADER & FOOTER
% ============================================
\usepackage[
  automark,
  markcase=upper% <- uppercase for left and right marks
]{scrlayer-scrpage}
\clearpairofpagestyles
\ohead{\headmark}% <- changed
\ofoot*{\pagemark}
\setkomafont{pagehead}{\sffamily\bfseries\upshape\textls*[75]}% \textls must be the last command
\addtokomafont{pagenumber}{\sffamily\bfseries}

\begin{document}
\chapter{Introduction}
\section{Section}
\newpage
Lorem ipsum
\end{document}

但请注意 KOMA-Script 文档中的这句话:

除此之外,印刷师一致认为,只要您将整个单词或短语设置为大写字母,就绝对需要额外的间距。但是,在所有字母之间添加固定间距并不是一个充分的解决方案。不同的字母对之间需要不同的间距。此外,一些字母已经在文本中产生了必须考虑的间隙。像 ulem 或 soul 这样的包几乎无法实现这一点,\MakeUppercase 也不能。使用 microtype 包的自动字母间距在这方面只是一个近似的解决方案,因为它没有考虑到具体的、依赖于字体的字形。因为排版全大写文本是专家工作,几乎总是需要手动调整,所以建议普通用户避免使用它,或者只谨慎使用它,不要在运行头等暴露的地方使用它

答案2

我认为以下内容与您的图片非常接近。请注意,如果您使用,重新定义\chapterlinesformat不会像使用那样执行任何操作。我希望所有内容都有评论,如果您不理解某些内容,请随时询问。\chapterlineswithprefixformatchapterprefix=true

\documentclass[
     paper = a4,
     twoside = false,
     numbers = noenddot,  
     parskip = half,
     listof = flat,
     listof = entryprefix,
     chapterprefix = true,
     listof = nochaptergap]{scrreprt}

% reduce vertical space between prefix and chapter title
\renewcommand\chapterheadmidvskip{\par\nobreak\smallskip}

% set font of the prefix
\setkomafont{chapterprefix}{\bfseries\LARGE}

% uppercasing of chapter title and raggedleft
\renewcommand\chapterlineswithprefixformat[3]
  {%
    \raggedleft
    #2\MakeUppercase{#3}%
  }

\renewcommand*{\sectionformat}{%
  \makebox[1.15cm][l]{\thesection\autodot}%
}
\renewcommand*{\subsectionformat}{%
  \makebox[1.15cm][l]{\thesubsection\autodot}%
}

% ============================================
% HEADER & FOOTER
% ============================================
\usepackage[automark]{scrlayer-scrpage}
\clearpairofpagestyles
\ohead{\MakeUppercase{\headmark}} %Chapter name in header
\ofoot*{\pagemark} %Page number
\setkomafont{pagehead}{\sffamily\bfseries\upshape}
\setkomafont{pagenumber}{\sffamily\bfseries\upshape}
\usepackage{etoolbox}

% patch the command which sets the header content to use
% \myheadchaptermarkformat instead of \chaptermarkformat
\patchcmd\chaptermark{chaptermarkformat}{myheadchaptermarkformat}{}{}% patching

% define \myheadchaptermarkformat to only include the number, not the prefix
\newcommand\myheadchaptermarkformat{\thechapter\autodot\enskip}

\begin{document}
\tableofcontents
\chapter{Introduction}
\section{Section}
\newpage
Lorem ipsum
\end{document}

本章的输出:

enter image description here

页面头的输出:

enter image description here

下面将soul\so宏添加到标题和页眉中的章节名称中。它以一种黑客的方式实现这一点,我不推荐它,也不知道下面的代码有多稳定,它适用于 MWE,但我不能保证它能正常工作。

\documentclass[
     paper = a4,
     twoside = false,
     numbers = noenddot,  
     parskip = half,
     listof = flat,
     listof = entryprefix,
     chapterprefix = true,
     listof = nochaptergap]{scrreprt}

% reduce vertical space between prefix and chapter title
\renewcommand\chapterheadmidvskip{\par\nobreak\smallskip}

\usepackage{soul}
% set font of the prefix
\setkomafont{chapterprefix}{\bfseries\LARGE}

% uppercasing of chapter title and raggedleft
\renewcommand\chapterlineswithprefixformat[3]
  {%
    \raggedleft
    #2\mychapterformatter{#3}%
  }
\makeatletter
\newcommand\mychapterformatter[1]
  {%
    \begingroup
    \let\interlinepenalty@original\interlinepenalty
    \let\interlinepenalty\my@interlinepenalty
    #1%
    \endgroup
  }
\newcommand\my@interlinepenalty{}
\long\def\my@interlinepenalty\@M#1\@@par%
  {%
    \interlinepenalty@original\@M
    \MakeUppercase{\so{#1}}%
    \@@par
  }
\makeatother

\renewcommand*{\sectionformat}{%
  \makebox[1.15cm][l]{\thesection\autodot}%
}
\renewcommand*{\subsectionformat}{%
  \makebox[1.15cm][l]{\thesubsection\autodot}%
}

% ============================================
% HEADER & FOOTER
% ============================================
\usepackage[automark]{scrlayer-scrpage}
\clearpairofpagestyles
\ohead{\MakeUppercase{\headmark}} %Chapter name in header
\ofoot*{\pagemark} %Page number
\setkomafont{pagehead}{\sffamily\bfseries\upshape}
\setkomafont{pagenumber}{\sffamily\bfseries\upshape}
\usepackage{etoolbox}

% patch the command which sets the header content to use
% \myheadchaptermarkformat instead of \chaptermarkformat
\patchcmd\chaptermark{chaptermarkformat}{myheadchaptermarkformat}{}{}% patching
\patchcmd\chaptermark{#1}{\so{#1}}{}{}

% define \myheadchaptermarkformat to only include the number, not the prefix
\newcommand\myheadchaptermarkformat{\thechapter\autodot\enskip\enskip}

\begin{document}
\tableofcontents
\chapter{Introduction}
\section{Section}
\newpage
\MakeUppercase{\so{Lorem ipsum}}
\end{document}

相关内容