附录条目带冒号,仅在目录中,但不在 pdfbookmark 中

附录条目带冒号,仅在目录中,但不在 pdfbookmark 中

我正在使用 scrreprt-class,并尝试修改 pdfbookmark 中附录标题的外观。

在下面的图片中,你可以看到我目前拥有的内容。我正在使用附录环境,每个附录都是一个独立的章节。

现在,我“仅”想在目录中为附录条目添加冒号。例如附录 A:我是附录 a,等等。

请注意,我想坚持使用 KOMA 级“scrreprt”。

提前致谢。

在此处输入图片描述

MWE(这是我的第一个 - 所以我不确定它是否尽可能小)

 \documentclass[12pt, longdoc, bigchapter, colorback, numbersubsubsec, twoside, openright, chapterprefix]{scrreprt}

\usepackage[ngerman]{babel}      % deutsche Trennregeln
\usepackage{lmodern}             % fixes bug with \usepackage[T1]{fontenc}; ändert Schriftart zudem in Latin Modern
\usepackage[T1]{fontenc}         % für europäische Autoren ratsam; % wichtig für Trennung von Wörtern mit Umlauten
\usepackage[utf8]{inputenc}


\usepackage{hyperref}           
\hypersetup{linktocpage=true,  linktoc=all,bookmarks=true, bookmarksopen=true, colorlinks, linkcolor = black}
\usepackage[all]{hypcap}        % needed to help hyperlinks direct correctly;
\usepackage[numbered]{bookmark}
\usepackage{booktabs}

%https://tex.stackexchange.com/questions/202928/remove-last-dot-in-title-numbering
\makeatletter
\g@addto@macro{\appendix}{%
    \patchcmd{\@@makechapterhead}% <cmd>
    {\endgraf\nobreak\vskip.5\baselineskip}% <search>
    {\hspace*{-0.5em}:\space}% <replace>
    {}{}% <success><failure>
    \patchcmd{\@chapter}% <cmd>
    {\addchaptertocentry{\thechapter}}% <search>
    {\addchaptertocentry{Appendix~\thechapter:}}% <replace>
    {}{}% <success><failure>
    \addtocontents{toc}{%
        \protect\patchcmd{\protect\l@chapter}% <cmd>
        {1.5em}% <search>
        {6.5em}% <replace>
        {}{}}% <success><failure>
}
\renewcommand{\autodot}{}% Remove all end-of-counter dots

%%% No Spacing Between Chapter Title and Prefix
\RedeclareSectionCommand[innerskip=0pt]{chapter} % <--- Vary distance here (Thanks @esdd!)


\usepackage[titletoc]{appendix}
\usepackage{lipsum}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}

%%% TOC
\phantomsection                             
\pdfbookmark{Inhaltsverzeichnis}{toc}   %Inhaltsverzeichnis in die Hyperlink-Navigation mit aufnehmen 
%\addcontentsline{toc}{chapter}{Inhaltsverzeichnis}
\setcounter{tocdepth}{4}
\tableofcontents

%%% Testpage
\chapter{Test}
\lipsum

%%%% APPENDIX
\begin{appendices}
\renewcommand\chaptername{Anhang}
\chapter{This is a test heading}
\end{appendices}


\end{document}

答案1

scrreprt这是针对 KOMA-Script 类但不带包的建议appendix

\documentclass[
  12pt,
  twoside,
  openright,
  chapterprefix,
  numbers=noenddot% <- added: no dots at the end of section numbers etc.
]{scrreprt}

\usepackage[ngerman]{babel}
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage{hyperref}
\hypersetup{linktoc=all,bookmarksopen=true, colorlinks, linkcolor = black}
\usepackage[all]{hypcap}        % needed to help hyperlinks direct correctly;
\usepackage[numbered]{bookmark}
\usepackage{booktabs}

\RedeclareSectionCommand[innerskip=0pt]{chapter} % <--- Vary distance here (Thanks @esdd!)

\DeclareTOCStyleEntry[
  level=\chaptertocdepth,
  indent=0pt,
  numwidth=2.3em,
  dynnumwidth,
  entrynumberformat=\appendixtocnumberformat,
]{chapter}{appendixchapter}
\newcommand*\appendixtocnumberformat[1]
  {\def\autodot{:}#1}

\usepackage{xpatch}
\xapptocmd{\appendix}
  {%
    \xpatchcmd{\chapterformat}{\autodot}{:}{}{\PatchFailedII}%
    \xpatchcmd{\chaptermarkformat}{\autodot}{:}{}{\PatchFailedIII}%
    \xpatchcmd{\addchaptertocentry}
      {\addtocentrydefault{chapter}{#1}{#2}}
      {%
        \ifstr{#1}{}
          {\addtocentrydefault{chapter}{}{#2}}
          {\addtocentrydefault{appendixchapter}{\appendixname\ #1}{#2}}%
      }{}{\PatchFailedIV}%
  }{}{\PatchFailedI}

\usepackage{lipsum}% only for dummy text
\begin{document}
\phantomsection
\pdfbookmark{Inhaltsverzeichnis}{toc}   %Inhaltsverzeichnis in die Hyperlink-Navigation
\setcounter{tocdepth}{4}
\tableofcontents

\chapter{Test}
\lipsum

\appendix
\chapter{This is a test heading}
\end{document}

运行三次得到:

在此处输入图片描述

在此处输入图片描述

请注意,我已删除未使用的全局选项longdoc, bigchapter, colorback, numbersubsubsec


因为下面评论中有一个疑问:

如果冒号也应该在书签中,则必须将其添加到以下\addtocentrydefault{appendixchapter}{...}{...}行:

\addtocentrydefault{appendixchapter}{\appendixname\ #1:}{#2}

并改变\autodot中的重新定义\appendixtocnumberformat

\newcommand*\appendixtocnumberformat[1]
  {\def\autodot{}#1}

书签中也包含冒号的完整示例:

\documentclass[
  12pt,
  twoside,
  openright,
  chapterprefix,
  numbers=noenddot% <- added: no dots at the end of section numbers etc.
]{scrreprt}

\usepackage[ngerman]{babel}
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage{hyperref}
\hypersetup{linktoc=all,bookmarksopen=true, colorlinks, linkcolor = black}
\usepackage[all]{hypcap}        % needed to help hyperlinks direct correctly;
\usepackage[numbered]{bookmark}
\usepackage{booktabs}

\RedeclareSectionCommand[innerskip=0pt]{chapter} % <--- Vary distance here (Thanks @esdd!)

\DeclareTOCStyleEntry[
  level=\chaptertocdepth,
  indent=0pt,
  numwidth=2.3em,
  dynnumwidth,
  entrynumberformat=\appendixtocnumberformat,
]{chapter}{appendixchapter}
\newcommand*\appendixtocnumberformat[1]
  {\def\autodot{}#1}% <- changed

\usepackage{xpatch}
\xapptocmd{\appendix}
  {%
    \xpatchcmd{\chapterformat}{\autodot}{:}{}{\PatchFailedII}%
    \xpatchcmd{\chaptermarkformat}{\autodot}{:}{}{\PatchFailedIII}%
    \xpatchcmd{\addchaptertocentry}
      {\addtocentrydefault{chapter}{#1}{#2}}
      {%
        \ifstr{#1}{}
          {\addtocentrydefault{chapter}{}{#2}}
          {\addtocentrydefault{appendixchapter}{\appendixname\ #1:}{#2}}% <- changed
      }{}{\PatchFailedIV}%
  }{}{\PatchFailedI}

\usepackage{lipsum}% only for dummy text
\begin{document}
\phantomsection
\pdfbookmark{Inhaltsverzeichnis}{toc}   %Inhaltsverzeichnis in die Hyperlink-Navigation
\setcounter{tocdepth}{4}
\tableofcontents

\chapter{Test}
\lipsum

\appendix
\chapter{This is a test heading}
\end{document}

结果: 在此处输入图片描述

答案2

memoir这不是一个真正的答案,但在这里我如何使用类来完成它

\documentclass[a4paper]{memoir}

\usepackage[ngerman]{babel}      % deutsche Trennregeln
\usepackage{lmodern}             % fixes bug with \usepackage[T1]{fontenc}; ändert Schriftart zudem in Latin Modern
\usepackage[T1]{fontenc}         % für europäische Autoren ratsam; % wichtig für Trennung von Wörtern mit Umlauten
\usepackage[utf8]{inputenc}


\usepackage{hyperref}           
\hypersetup{linktocpage=true,  linktoc=all,bookmarks=true, bookmarksopen=true, colorlinks, linkcolor = black}
\usepackage[numbered]{bookmark}

%\renewcommand\cftchaptername{\chaptername~}
\renewcommand\cftappendixname{\appendixname~}
\makeatletter
\AtBeginDocument{
\bookmarksetup{%
 addtohook={%
   \ifnum\toclevel@chapter=\bookmarkget{level}\relax
     \ifanappendix
       \renewcommand*{\chapternumberline}[1]{\appendixname~#1:~}%
     \fi  
   \fi
 },
}
}
\makeatother

\cftinsertcode{APP}{
  \renewcommand\cftchapteraftersnum{:~}
}

\usepackage{lipsum}


\begin{document}

%%% TOC
\phantomsection                             
\pdfbookmark{Inhaltsverzeichnis}{toc}   %Inhaltsverzeichnis in die Hyperlink-Navigation mit aufnehmen 
%\addcontentsline{toc}{chapter}{Inhaltsverzeichnis}
\setcounter{tocdepth}{4}
\tableofcontents*

%%% Testpage
\chapter{Test}
\lipsum

%%%% APPENDIX
%\begin{appendices}

\appendix

\cftinserthook{toc}{APP}


\chapter{This is a test heading}
%\end{appendices}


\end{document}

答案3

一个独立于文档类的解决方案是简单地为目录指定一个包含冒号的替代章节名称,然后使用 \hspace 来纠正间距。即,不要使用

\chapter{This is a test heading}

可以使用

\chapter[\hspace{-0.3cm}: This is a test heading]{This is a test heading}

在此处输入图片描述

更新:正如 egreg 指出的那样,上述解决方案也会更改标题。由于“附录”并不总是打印在标题中,因此可以使用 fancyhdr 来弥补这一点。例如

\fancyhead[LO, RE]{\fancyplain{}{\appendixname\hspace{1ex}\thechapter \hspace{0.3cm}\nouppercase\leftmark}}

相关内容