更改 autorefnames 在标题中插入空格

更改 autorefnames 在标题中插入空格

我使用hyperrefautoref,但重新定义了 autorefnames。我使用 将章节和部分名称放入我的页眉中scrlayer-scrpage。有一些不需要的空间,总是在标题的左侧......无论我在偶数页还是奇数页。当章节或部分名称太长而无法放入标题中时,这一点尤其明显。在示例中,它们原则上可以放入,但由于空间原因,它们不能放入。

如果我不重命名autorefs,一切都会正常。这是怎么回事?我该如何修复?

我试过了“狼吞虎咽”,在新的之前和之后\...autorefname,但这没有帮助。

\documentclass[pdfa,a4paper,
               11pt,
               bibliography=totoc,
               numbers=noenddot,
               twoside,openright,
               parskip=half]{scrbook}
\usepackage{lipsum}
% ********************************************************************
% Languages, Typesetting
% ******************************************************************** 
\usepackage[ngerman, english]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}         %windows: latin9, linux: utf8

% ********************************************************************
% page layout
% ********************************************************************
\usepackage[]{scrlayer-scrpage}
\renewcommand{\chapterpagestyle}{empty} % no headings or footings on first chapter page
\renewcommand{\chaptermark}[1]{\markboth{{#1}}{{#1}}}
\renewcommand{\sectionmark}[1]{\markright{\upshape{\thesection}\enspace{#1}}}
\lehead{\mbox{\llap{\small\upshape\thepage\kern2em}\scshape\headmark\hfil}}
\rohead{\mbox{\hfil{\scshape\headmark}\rlap{\small\kern2em\upshape\thepage}}}
\chead{}\ifoot{}\cfoot{}\ofoot{}
\pagestyle{scrheadings}

% ********************************************************************
% Hyperreferences, always load last
% ********************************************************************
\usepackage[]{hyperref}
% Commenting this whole block fixes the problem
\makeatletter
\@ifpackageloaded{babel}
{
    \addto\extrasenglish{
        \renewcommand*{\figureautorefname}{Figure}
        \renewcommand*{\tableautorefname}{Table}
        \renewcommand*{\partautorefname}{Part}
        \renewcommand*{\chapterautorefname}{Chapter}
        \renewcommand*{\sectionautorefname}{Section}
        \renewcommand*{\subsectionautorefname}{Section}
        \renewcommand*{\subsubsectionautorefname}{Section}
        \renewcommand*{\appendixautorefname}{Appendix}
    }
}{\relax}
\makeatother


\begin{document}
\part{Intro}
\chapter{Short chapter name}
\lipsum[1]
\section{Short section name}
\lipsum
\lipsum
\chapter{Very long chapter name just not fitting into the headline}
\lipsum[1]
\section{Very long section name just not fitting into the headline}
\lipsum
\lipsum
\end{document}

答案1

您可以使用

\AfterPackage*{babel}
{
  \renewcaptionname{english}{\figureautorefname}{Figure}
  \renewcaptionname{english}{\tableautorefname}{Table}
  \renewcaptionname{english}{\partautorefname}{Part}
  \renewcaptionname{english}{\chapterautorefname}{Chapter}
  \renewcaptionname{english}{\sectionautorefname}{Section}
  \renewcaptionname{english}{\subsectionautorefname}{Section}
  \renewcaptionname{english}{\subsubsectionautorefname}{Section}
  \renewcaptionname{english}{\appendixautorefname}{Appendix}
}

\AfterPackage*scrlfile由 KOMA-Script 类自动加载的包定义。\renewcaptionname也是一个 KOMA-Script 命令。

另外,我会将页面布局的设置更改为

\renewcommand{\chapterpagestyle}{empty} % no headers or footers on first chapter page
\usepackage[]{scrlayer-scrpage}
\automark[chapter]{chapter}
\automark*[section]{}
\renewcommand\chaptermarkformat{}% no chapter number in header/footer
\addtokomafont{pagehead}{\scshape}
\addtokomafont{pagenumber}{\small}
\clearmainofpairofpagestyles
\lehead{\mbox{\llap{\pagemark\kern2em}\headmark}}
\rohead{\mbox{{\ifstr{\leftmark}{\rightmark}{}{\upshape}\headmark}\rlap{\kern2em\pagemark}}}

例子:

\documentclass[pdfa,a4paper,
               11pt,
               bibliography=totoc,
               numbers=noenddot,
               twoside,openright,
               parskip=half]{scrbook}
\usepackage{lipsum}
% ********************************************************************
% Languages, Typesetting
% ******************************************************************** 
\usepackage[ngerman, english]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

% ********************************************************************
% page layout
% ********************************************************************
\renewcommand{\chapterpagestyle}{empty} % no headers or footers on first chapter page
\usepackage[]{scrlayer-scrpage}
\automark[chapter]{chapter}
\automark*[section]{}
\renewcommand\chaptermarkformat{}%  no chapter number in header/footer
\addtokomafont{pagehead}{\scshape}
\addtokomafont{pagenumber}{\small}
\clearmainofpairofpagestyles
\lehead{\mbox{\llap{\pagemark\kern2em}\headmark}}
\rohead{\mbox{{\ifstr{\leftmark}{\rightmark}{}{\upshape}\headmark}\rlap{\kern2em\pagemark}}}

% ********************************************************************
% Hyperreferences, always load last
% ********************************************************************
\usepackage[]{hyperref}

\AfterPackage*{babel}
{
  \renewcaptionname{english}{\figureautorefname}{Figure}
  \renewcaptionname{english}{\tableautorefname}{Table}
  \renewcaptionname{english}{\partautorefname}{Part}
  \renewcaptionname{english}{\chapterautorefname}{Chapter}
  \renewcaptionname{english}{\sectionautorefname}{Section}
  \renewcaptionname{english}{\subsectionautorefname}{Section}
  \renewcaptionname{english}{\subsubsectionautorefname}{Section}
  \renewcaptionname{english}{\appendixautorefname}{Appendix}
}

\begin{document}
\part{Intro}
\chapter{Short chapter name}
\lipsum[1]
\section{Short section name}
\lipsum
\lipsum
\chapter{Very long chapter name just not fitting into the headline}
\lipsum[1]
\section{Very long section name just not fitting into the headline}
\lipsum
\lipsum
\end{document}

在此处输入图片描述


更新:关于评论的另一个例子:

\documentclass[pdfa,a4paper,
               11pt,
               bibliography=totoc,
               numbers=noenddot,
               twoside,openright,
               parskip=half]{scrbook}
\usepackage{lipsum}
% ********************************************************************
% Languages, Typesetting
% ******************************************************************** 
\usepackage[ngerman, english]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{microtype}

\usepackage{textcase}
\DeclareRobustCommand{\spacedlowsmallcaps}[1]{\textls[80]{\scshape\MakeTextLowercase{#1}}}
% ********************************************************************
% page layout
% ********************************************************************
\renewcommand{\chapterpagestyle}{empty} % no headers or footers on first chapter page
\usepackage[]{scrlayer-scrpage}
\automark[chapter]{chapter}
\automark*[section]{}
\renewcommand*\chaptermarkformat{}%  no chapter number in header/footer
\renewcommand*\sectionmarkformat{{\small\thesection\autodot\enskip}}% section number using \small
\addtokomafont{pagenumber}{\small}% page number using \small
\clearmainofpairofpagestyles% remove all default entries for page style scrheadings
\lehead{\mbox{\llap{\pagemark\kern2em}\spacedlowsmallcaps{\headmark}}}
\rohead{\mbox{\spacedlowsmallcaps{\headmark}\rlap{\kern2em\pagemark}}}

% ********************************************************************
% Hyperreferences, always load last
% ********************************************************************
\usepackage[]{hyperref}

\AfterPackage*{babel}
{
  \renewcaptionname{english}{\figureautorefname}{Figure}
  \renewcaptionname{english}{\tableautorefname}{Table}
  \renewcaptionname{english}{\partautorefname}{Part}
  \renewcaptionname{english}{\chapterautorefname}{Chapter}
  \renewcaptionname{english}{\sectionautorefname}{Section}
  \renewcaptionname{english}{\subsectionautorefname}{Section}
  \renewcaptionname{english}{\subsubsectionautorefname}{Section}
  \renewcaptionname{english}{\appendixautorefname}{Appendix}
}

\begin{document}
\part{Intro}
\chapter{Short chapter name}
\lipsum[1]
\section{Short section name}
\lipsum
\lipsum
\chapter{Very long chapter name just not fitting into the headline}
\lipsum[1]
\section{Very long section name just not fitting into the headline}
\lipsum
\lipsum
\end{document}

请注意,您不能使用\MakeTextLowercasein\setkomafont\addtokomafont。因此,您必须插入\spacedlowsmallcapsin \leheadany \rohead

答案2

任何\renewcommand*{\....autorefname}{...}语句都会导致额外的空格字符,因为它是\extraenglish在排版期间调用的,而不是在序言中完成的。

%在每行末尾添加。

\documentclass[pdfa,a4paper,
               11pt,
               bibliography=totoc,
               numbers=noenddot,
               twoside,openright,
               parskip=half]{scrbook}
\usepackage{lipsum}
% ********************************************************************
% Languages, Typesetting
% ******************************************************************** 
\usepackage[ngerman, english]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}         %windows: latin9, linux: utf8

% ********************************************************************
% page layout
% ********************************************************************
\usepackage[]{scrlayer-scrpage}
\renewcommand{\chapterpagestyle}{empty} % no headings or footings on first chapter page
\renewcommand{\chaptermark}[1]{\markboth{{#1}}{{#1}}}
\renewcommand{\sectionmark}[1]{\markright{\upshape{\thesection}\enspace{#1}}}
\lehead{\mbox{\llap{\small\upshape\thepage\kern2em}\scshape\headmark\hfil}}
\rohead{\mbox{\hfil{\scshape\headmark}\rlap{\small\kern2em\upshape\thepage}}}
\chead{}\ifoot{}\cfoot{}\ofoot{}
\pagestyle{scrheadings}

% ********************************************************************
% Hyperreferences, always load last
% ********************************************************************
\usepackage[]{hyperref}
% Commenting this whole block fixes the problem
\makeatletter
\@ifpackageloaded{babel}
{
  \addto\extrasenglish{%
    \renewcommand*{\figureautorefname}{Figure}%
    \renewcommand*{\tableautorefname}{Table}%
    \renewcommand*{\partautorefname}{Part}%
    \renewcommand*{\chapterautorefname}{Chapter}%
    \renewcommand*{\sectionautorefname}{Section}%
    \renewcommand*{\subsectionautorefname}{Section}%
    \renewcommand*{\subsubsectionautorefname}{Section}%
    \renewcommand*{\appendixautorefname}{Appendix}%
  }%
}{\relax}
\makeatother


\begin{document}
\part{Intro}
\chapter{Short chapter name}
\lipsum[1]
\section{Short section name}
\lipsum
\lipsum
\chapter{Very long chapter name just not fitting into the headline}
\lipsum[1]
\section{Very long section name just not fitting into the headline}
\lipsum
\lipsum
\end{document}

相关内容