将章节和节标题与外边缘对齐

将章节和节标题与外边缘对齐

我正在尝试实现以下结果(使用 Photoshop 制作):

我已经设法正确格式化正确的页面,但这对双面文档显然不起作用:

\documentclass[a4paper,11pt,twoside,chapterprefix=true]{scrbook}

\usepackage{lipsum}
\usepackage[includehead,
            top=25mm,
            left=40mm,
            right=35mm
]{geometry}

\makeatletter
\def\@seccntformat#1{\llap{\csname the#1\endcsname\quad}}
\makeatother

\begin{document}
\chapter{Sample}
\section{This Is a First Level Section} \lipsum[1]
\subsection{And Second Level} \lipsum[2] \pagebreak
\section{First Level Again} \lipsum[3]
\subsection{Second Level} \lipsum[4]    
\end{document}

我怎样才能将标题与外边缘对齐?

答案1

有人问过 Markus。KOMA-Script 网站上有两条建议:用兰特数字表示兰特的缩写(德语)。 这两个建议都需要进行一些运行才能得到正确的数字。

第一个解决方案需要 KOMA-Script 3.19a 或更新版本。我对此代码做了一些修改,现在它也可以适用于较长的章节标题。

\documentclass[chapterprefix]{scrbook}
%\providecommand*\Ifthispageodd{\ifthispageodd}% needed up to and including KOMA-Script version 3.27, see https://komascript.de/faq_deprecatedif
\usepackage{blindtext}% dummy text
\renewcommand*{\raggedsection}{\Ifthispageodd{\raggedleft}{\raggedright}}
\renewcommand*{\sectionlinesformat}[4]{%
  \ifthispagewasodd
    \parbox[t]{\linewidth}{\leavevmode\raggedsection#4}\makebox[0pt][l]{\hskip\marginparsep #3}%
  \else
    \makebox[0pt][r]{#3\hskip\marginparsep}#4%
  \fi
}
\renewcommand*{\sectionformat}{\thesection\autodot}
\renewcommand*{\subsectionformat}{\thesubsection\autodot}
\renewcommand*{\subsubsectionformat}{\thesubsubsection\autodot}
\begin{document}
\chapter{A Chapter}
\section{A section with a long, long, long title that needs more than one line}
\Blindtext
\section{Another section}
\blindtext
\blinddocument
\end{document}

在此处输入图片描述

在此处输入图片描述

第二个示例使用包marginnote,但也适用于旧版本的 KOMA-Script。

\documentclass[chapterprefix]{scrbook}
%\providecommand*\Ifthispageodd{\ifthispageodd}% needed up to and including KOMA-Script version 3.27, see https://komascript.de/faq_deprecatedif
\usepackage{marginnote}
\usepackage{mwe}
\renewcommand*{\raggedsection}{\Ifthispageodd{\raggedleft}{\raggedright}}
\renewcommand*{\sectionformat}{%
  \marginnote{%
    \usekomafont{disposition}{\usekomafont{section}{%
        \thesection\autodot}}}}
\renewcommand*{\subsectionformat}{%
  \marginnote{%
    \usekomafont{disposition}{\usekomafont{subsection}{%
        \thesubsection\autodot}}}}
\renewcommand*{\subsubsectionformat}{%
  \marginnote{%
    \usekomafont{disposition}{\usekomafont{subsubsection}{%
        \thesubsubsection\autodot}}}}
\begin{document}
\chapter{A chapter}
\section{A section with a long, long, long title that needs more than one line}
\Blindtext
\section{Another section}
\blindtext
\blinddocument
\end{document}

相关内容