scrbook 类文档页眉中章节标题第二行的缩进

scrbook 类文档页眉中章节标题第二行的缩进

我有一个自定义scrbook类文档和一个很长的章节标题,在页眉中打印标题时会产生换行符。第二行的第一个字符与第一行的第一个字符不对齐;而是与章节号对齐。我该如何修复这个问题?

梅威瑟:

\documentclass{test}
\usepackage[utf8]{inputenc}

\usepackage{hyperref}

\begin{document}

\chapter[A Bcdefg hijklmnop qrstuvwx yz abc defghij klmnopq rs tuv wxyzab cdef Ghijklmnop Qrstuvwx yzabcdefg]{\texorpdfstring{A Bcdefg hijklmnop qrstuvwx yz abc defghij klmnopq\newline rs tuv wxyzab cdef Ghijklmnop Qrstuvwx yzabcdefg}{A Bcdefg hijklmnop qrstuvwx yz abc defghij klmnopq rs tuv wxyzab cdef Ghijklmnop Qrstuvwx yzabcdefg}}

\newpage
.

\end{document}

测试.cls:

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{test}

\LoadClass[a4paper, 12pt, twoside, openright, BCOR=1.5cm, appendixprefix, cleardoublepage=empty, numbers=noenddot, bibliography=totoc]{scrbook}

\RequirePackage[T1]{fontenc}
\RequirePackage[utf8]{inputenc}
\RequirePackage{lmodern}

\IfFileExists{scrlayer-scrpage.sty}
{
    \RequirePackage[automark,headsepline]{scrlayer-scrpage}
}{
    \RequirePackage{fancyhdr}
}

\IfFileExists{scrlayer-scrpage.sty}
{
    \pagestyle{scrheadings}

    \clearpairofpagestyles
    \lefoot[\pagemark]{\pagemark}
    \rofoot[\pagemark]{\pagemark}
    \lehead{\headmark}
    \rohead{\headmark}
}{
    \pagestyle{fancy}

    \lhead[\fancyplain{}{\leftmark}]{}
    \rhead[]{\fancyplain{}{\rightmark}}
    \lfoot[\fancyplain{\thepage}{\thepage}]{}
    \rfoot[]{\fancyplain{\thepage}{\thepage}}
    \cfoot[]{}

    \fancypagestyle{plain}{
    \fancyhf{}
    \fancyfoot[LE,RO]{\thepage}
    \renewcommand{\headrulewidth}{0pt}
    \renewcommand{\footrulewidth}{0pt}
    }
}

\renewcommand{\chaptermark}[1]{\markboth{\textsc{\thechapter~#1}}{}}
\renewcommand{\sectionmark}[1]{\markright{\textsl{\thesection~#1}}}

答案1

我建议在标题中使用简短的标题:

\documentclass[
  %a4paper,% default
  12pt,
  %twoside, openright,% default for scrbook
  BCOR=1.5cm,
  appendixprefix,
  %cleardoublepage=empty,% default
  numbers=noenddot,
  bibliography=totoc,
  headings=optiontoheadandtoc% <- added!
]{scrbook}

\usepackage[T1]{fontenc}
%\usepackage[utf8]{inputenc}% only needed with older TeX Distributions
\usepackage{lmodern}

\usepackage[automark,headsepline]{scrlayer-scrpage}
\clearpairofpagestyles
\ofoot*{\pagemark}
\ohead{\headmark}

\renewcommand{\chaptermark}[1]{\markboth{\textsc{\thechapter~#1}}{}}
\renewcommand{\sectionmark}[1]{\markright{\textsl{\thesection~#1}}}

\usepackage{hyperref}

\begin{document}
\tableofcontents
\chapter[
  tocentry={A Bcdefg hijklmnop qrstuvwx yz abc defghij klmnopq rs tuv wxyzab cdef Ghijklmnop Qrstuvwx yzabcdefg},
  head={short title for header}
]{A Bcdefg hijklmnop qrstuvwx yz abc defghij klmnopq\newline rs tuv wxyzab cdef Ghijklmnop Qrstuvwx yzabcdefg}

\clearpage
.
\end{document}

在此处输入图片描述

补充说明:

  • 不要inputenc在类文件中加载包。如果确实需要包,则在文档文件本身中加载它。
  • 如果有 KOMA-Script 类可用,那么scrlayer-scrpage也会安装包。

如果您确实需要标题中章节标题的长版本:

\documentclass[
  %a4paper,% default
  12pt,
  %twoside, openright,% default for scrbook
  BCOR=1.5cm,
  appendixprefix,
  %cleardoublepage=empty,% default
  numbers=noenddot,
  bibliography=totoc
]{scrbook}

\usepackage[T1]{fontenc}
%\usepackage[utf8]{inputenc}% only needed with older TeX Distributions
\usepackage{lmodern}

\usepackage[automark,headsepline]{scrlayer-scrpage}
\clearpairofpagestyles
\ofoot*{\pagemark}
\ohead{\headmark}

\makeatletter% <- added
\renewcommand{\chaptermark}[1]{\markboth{\scshape\@hangfrom{\thechapter~}{#1}}{}}% <- changed
\renewcommand{\sectionmark}[1]{\markright{\slshape\@hangfrom{\thesection~}{#1}}}% <- changed
\makeatother% <- added

\usepackage{hyperref}

\KOMAoptions{headlines=2.1}% <-added
\recalctypearea% <- added

\begin{document}
\tableofcontents
\chapter
  [A Bcdefg hijklmnop qrstuvwx yz abc defghij klmnopq rs tuv wxyzab cdef Ghijklmnop Qrstuvwx yzabcdefg]
  {A Bcdefg hijklmnop qrstuvwx yz abc defghij klmnopq\newline rs tuv wxyzab cdef Ghijklmnop Qrstuvwx yzabcdefg}

\clearpage
.
\end{document}

请注意,您必须在文档的前言中为headlinesheadheight后跟设置适当的值。\recalctypearea

在此处输入图片描述

相关内容