scrreport 文档类的大写章节标题和目录

scrreport 文档类的大写章节标题和目录

我正在尝试结合scrartcl 目录中的大写字母、斜体和超链接,不使用 tocstyle带有 KOMA 字体的大写章节

\renewcommand\addsectiontocentry[2]{%
  \addtocentrydefault{section}{#1}{\texorpdfstring{\MakeUppercase{#2}}{#2}}%
}
\renewcommand\addsubsectiontocentry[2]{%
  \addtocentrydefault{subsection}{#1}{\texorpdfstring{\MakeUppercase{#2}}{#2}}%
}
\renewcommand\addsubsubsectiontocentry[2]{%
  \addtocentrydefault{subsubsection}{#1}{\texorpdfstring{\MakeUppercase{#2}}{#2}}%
}

\makeatletter
\renewcommand\sectionlinesformat[4]{%
  \@hangfrom{\hskip#2#3}{\MakeUppercase{#4}}%
}
\makeatother

但是,TOC 链接无法指向任何地方。有什么办法可以解决这个问题吗?

我尝试更换

  \addtocentrydefault{section}{#1}{\texorpdfstring{\MakeUppercase{#2}}{#2}}%

  \addtocentrydefault{section}{#1}{\texorpdfstring{\MakeUppercase{#2}}{\MakeUppercase{#2}}}%

但我得到了\MakeUppercase ...ppercaseUnsupportedInPdfStrings错误。该文档是用 pandoc 生成的,所以我只能添加一些 latex 片段。

我对 LaTeX 还很陌生,因此我不仅非常希望得到解决方案,而且还希望得到任何关于如何自己调试此类问题的提示。

UPD:下面是一个最小的可重现示例:

% Run "xelatex example.tex" (twice) to compile to pdf
\documentclass{scrartcl}
\usepackage{blindtext}% only for dummy text
\setcounter{tocdepth}{\subsubsectiontocdepth}

\renewcommand\addsectiontocentry[2]{%
  \addtocentrydefault{section}{#1}{\texorpdfstring{\MakeUppercase{#2}}{#2}}%
}
\renewcommand\addsubsectiontocentry[2]{%
  \addtocentrydefault{subsection}{#1}{\texorpdfstring{\MakeUppercase{#2}}{#2}}%
}
\renewcommand\addsubsubsectiontocentry[2]{%
  \addtocentrydefault{subsubsection}{#1}{\texorpdfstring{\MakeUppercase{#2}}{#2}}%
}

\makeatletter
\renewcommand\sectionlinesformat[4]{%
  \@hangfrom{\hskip #2#3}{\MakeUppercase{#4}}%
}
\makeatother
\renewcommand{\sectioncatchphraseformat}[4]{%
  \hskip #2#3\MakeUppercase{#4}%
}

\usepackage{hyperref}

% This command breaks TOC hyperlinks
\setcounter{secnumdepth}{-\maxdimen} % remove section numbering

\begin{document}
\tableofcontents
\blinddocument
\blinddocument
\end{document}

答案1

更新

即使我添加了代码,它仍然对我有用,但我使用的是最新的 KOMA-Script 版本 3.31(2020/07/22)。在以前的版本中,未编号的部分\setcounter{secnumdepth}{-\maxdimen}存在问题,请参阅hyperrefKOMA-Script 3.30 中出现的问题和挑战(德语)。所以也许你必须更新。

% Run "xelatex example.tex" (twice) to compile to pdf
\documentclass{scrartcl}[2020/07/22]% version 3.31 or newer
\usepackage{blindtext}% only for dummy text
\setcounter{tocdepth}{\subsubsectiontocdepth}

\renewcommand\addsectiontocentry[2]{%
  \addtocentrydefault{section}{#1}{\texorpdfstring{\MakeUppercase{#2}}{#2}}%
}
\renewcommand\addsubsectiontocentry[2]{%
  \addtocentrydefault{subsection}{#1}{\texorpdfstring{\MakeUppercase{#2}}{#2}}%
}
\renewcommand\addsubsubsectiontocentry[2]{%
  \addtocentrydefault{subsubsection}{#1}{\texorpdfstring{\MakeUppercase{#2}}{#2}}%
}

\makeatletter
\renewcommand\sectionlinesformat[4]{%
  \@hangfrom{\hskip #2#3}{\MakeUppercase{#4}}%
}
\makeatother
\renewcommand{\sectioncatchphraseformat}[4]{%
  \hskip #2#3\MakeUppercase{#4}%
}

\usepackage{hyperref}

% This command breaks TOC hyperlinks
\setcounter{secnumdepth}{-\maxdimen} % remove section numbering

\begin{document}
\KOMAScriptVersion% added to show the KOMA-Script version in the document
\tableofcontents
\blinddocument
\blinddocument
\end{document}

在此处输入图片描述

原始答案

渴望评论:

以下示例对我有用。

\documentclass{scrartcl}
\usepackage{blindtext}% only for dummy text
\setcounter{tocdepth}{\subsectiontocdepth}

\makeatletter
\renewcommand\sectionlinesformat[4]{%
  \@hangfrom{\hskip#2#3}{\MakeUppercase{#4}}%
}
\makeatother
\renewcommand{\sectioncatchphraseformat}[4]{%
  \hskip#2#3\MakeUppercase{#4}%
}

\renewcommand\addsectiontocentry[2]{%
  \addtocentrydefault{section}{#1}{\texorpdfstring{\MakeUppercase{#2}}{#2}}%
}
\renewcommand\addsubsectiontocentry[2]{%
  \addtocentrydefault{subsection}{#1}{\texorpdfstring{\MakeUppercase{#2}}{#2}}%
}

\usepackage{hyperref}

\begin{document} 
\tableofcontents
\blinddocument
\blinddocument
\end{document}

结果:

在此处输入图片描述

相关内容