我希望添加的章节标题与\chapter{title}
右侧对齐(即与\raggedleft
),但其他所有归类为章节的内容(即添加的章节\addchap{title}
或参考书目的标题)保持与页面左侧对齐。
我找到的解决方案是将每个章节的标题向左对齐。是否可以在文档内本地更改此设置?
梅威瑟:
\documentclass[chapterprefix=true]{scrreprt}
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage{lipsum}
\renewcommand{\raggedchapter}{\raggedleft}
\begin{document}
\chapter{The first chapter}
\lipsum[1-3]
\addchap{A chapter that should be flushleft}
\lipsum[4]
\end{document}
答案1
您可以重新定义\chapterlineswithprefixformat
:
\documentclass[chapterprefix=true]{scrreprt}
%\providecommand*\Ifstr{\ifstr}% needed up to and including KOMA-Script version 3.27, see https://komascript.de/faq_deprecatedif
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage{lipsum}
\newcommand*{\originalchapterlineswithprefixformat}{}
\let\originalchapterlineswithprefixformat\chapterlineswithprefixformat
\renewcommand\chapterlineswithprefixformat[3]{%
\Ifstr{#1}{chapter}
{\Ifstr{#2}{}{\raggedright}{\raggedleft}}
{}%
\originalchapterlineswithprefixformat{#1}{#2}{#3}
}
\begin{document}
\tableofcontents
\chapter{The first chapter}
\lipsum[1-3]
\addchap{A chapter that should be flushleft}
\lipsum[4]
\end{document}
结果:
KOMA-Script 版本 3.27提供额外的钩子。然后你可以使用
\documentclass[chapterprefix=true]{scrreprt}
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage{lipsum}
\AddtoDoHook{heading/begingroup/chapter}{\chapteralignment}
\newcommand*\chapteralignment[1]{%
\IfUseNumber{\let\raggedchapter\raggedleft}{\let\raggedchapter\raggedright}%
}
\begin{document}
\tableofcontents
\chapter{The first chapter}
\lipsum[1-3]
\addchap{A chapter that should be flushleft}
\lipsum[4]
\end{document}