變更 autorefnames 會在標頭中插入空格

變更 autorefnames 會在標頭中插入空格

我使用hyperrefand autoref,但重新定義了 autorefnames。我使用 . 將章節名稱放入頁首scrlayer-scrpage。有一些不需要的空間,總是在標題的左側......無論我在偶數頁還是奇數頁上都沒關係。當章節名稱太長而無法放入標題時,這一點尤其明顯。在這個範例中,它們原則上可以適合,但由於空間原因而不適合。

如果我不重命名 s autoref,一切都很好。這是怎麼回事,我該如何解決?

我試過了“狼吞虎嚥”,在 new 之前和之後\...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。因此,您必須\spacedlowsmallcaps插入\lehead任何\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}

相關內容