将目录中的标题大写,并将标题大写(使用 KOMA),并且不会丢失引用

将目录中的标题大写,并将标题大写(使用 KOMA),并且不会丢失引用

我正在努力将链接/书签与大写目录和大写标题结合起来。

首先,我努力将目录以及标题大写\subsections(是的,我知道这样看起来不太好看,但 Cooporate Design 要求这样做)。

我正在使用 TeXnicCenter 和 LuaLaTeX。由于使用了 documentclass koma-script,所以我正在寻找“tocloft”包的替代品

编辑:试图让我的问题清楚:

我几乎通过使用以下方法得到了我想要的东西\usepackage{tocloft}

\documentclass[
a4paper,
10pt,
oneside,
%chapterprefix,
%appendixprefix,
numbers=noenddot,
toc=chapterentrywithdots,
toc=listof
]{scrbook}

\usepackage{lipsum}
%\usepackage{blindtext}
\usepackage[]{appendix}         % to get the prefix Appendix infront of Appendix chapters



\usepackage[
bookmarks,
bookmarksopen=true,
bookmarksnumbered=true,
pdfauthor={ME},
pdftitle={SCRBook},
colorlinks,
%linkcolor=\color{blue},
%urlcolor=\color{blue},
plainpages=false,
unicode=true
]{hyperref} 


\setcounter{secnumdepth}{3}



%BEGIN - TOC consist only of Word "Appendix", and then on 1st page of appendix content of appendix
%https://tex.stackexchange.com/questions/585062/table-of-contents-with-appendix-short-and-a-new-toc-with-detailed-appendix/585195#585195
\DeclareNewTOC[%
owner=\jobname
]{atoc}

\makeatletter
\newcommand*{\useappendixtoc}{%
    \renewcommand*{\ext@toc}{atoc}%
    \scr@ifundefinedorrelax{hypersetup}{}{%
        \hypersetup{bookmarkstype=atoc}%
    }%
}
\makeatother

\usepackage{xpatch}

\xapptocmd\appendix{%
    \addchap{\appendixname}
    \listoftoc*{atoc}
    \useappendixtoc
}{}{}

%END - TOC consist only of Word Appendix


%%ALTERNATIVE1
% BEGIN Capitalize sections in TOC and LOF.
\usepackage{tocloft}
\usepackage{etoolbox}
\makeatletter
\patchcmd{\l@chapter}{#1}{\uppercase{#1}}{}{}       % Capitalize chapters.
\patchcmd{\l@section}{#1}{\uppercase{#1}}{}{}       % Capitalize sections.
\patchcmd{\l@subsection}{#1}{\uppercase{#1}}{}{}    % Capitalize subsections
\makeatother


%-----for headings in capital------
\usepackage[explicit]{titlesec} 

\def\tab#1{\parbox[t]{25mm}{#1}\hfill}

\titleformat{\chapter}{\large\bfseries}{\parbox[t]{13mm}{\thechapter}}{0mm}{\MakeUppercase{#1}}
\titleformat{name=\chapter,numberless}{\large\bfseries}{}{0mm}{\MakeUppercase{#1}}

\titleformat{\section}{\large\bfseries}{\parbox[t]{13mm}{\thesection}}{0mm}{\MakeUppercase{#1}}
\titleformat{name=\section,numberless}{\large\bfseries}{}{0mm}{\MakeUppercase{#1}}

\titleformat{\subsection}{\normalsize\bfseries}{\parbox[t]{13mm}{\thesubsection}}{0mm}{\MakeUppercase{#1}}
\titleformat{name=\subsection,numberless}{\normalsize\bfseries}{}{0mm}{#1}

\titleformat{\subsubsection}{\normalsize\bfseries}{\parbox[t]{13mm}{\thesubsubsection}}{0mm}{#1}
\titleformat{name=\subsubsection,numberless}{\normalsize\bfseries}{}{0mm}{#1}

\titlespacing{\chapter}{0pt}{12pt}{6pt}
\titlespacing{\section}{0pt}{12pt}{6pt}
\titlespacing{\subsection}{0pt}{6pt}{3pt}
\titlespacing{\subsubsection}{0pt}{6pt}{3pt}

\setlength{\headsep}{12pt}
% END Capitalize sections in TOC and LOF.


\begin{document}
    \begin{titlepage}
    \huge{\textbf{TITLE}}  \\
    \bigskip
    Here text for titlepage
        
    \end{titlepage} 
        
    
    \addchap{Executive Summary}
    \addsec{Executive subchapter1}
    \lipsum[1]
    \addsec{Executive subchapter2}
    \lipsum[2]
    \newpage
        
    \renewcommand{\contentsname}{Table of Content}  % WARNING: don't move to preamble  doesn't work there
    \setcounter{tocdepth}{6}              % how deep is the table of contents listed
    \setcounter{secnumdepth}{6}           % how deep are the sections numbered  
    \tableofcontents
    \listoffigures
    \listoftables
    

    \chapter{Chapter}
    \label{chap}
    \lipsum[1-5]
    \section{Section1}
    \lipsum[1-5]
    
    \begin{tabular}{||c|c|c|c|}
        \hline
        \rule[-1ex]{0pt}{2.5ex} a & b & c & d \\
        \hline
        \rule[-1ex]{0pt}{2.5ex} 1 & 2 & 3 & 4 \\
        \hline
        \rule[-1ex]{0pt}{2.5ex} 5 & 6 & 7 & 8 \\
        \hline
        \rule[-1ex]{0pt}{2.5ex} 9 & 10 & 11 & 12 \\
        

    \end{tabular}
    

    
    
    
    \section{Section2}
    \lipsum[1-5]
    \subsection{Subsection1}
    \lipsum[1-5]
    \subsection{Subsection2}
    \lipsum[1-5]
    \subsubsection{SubSubSection1}
    \lipsum[1-5]
    
    \chapter{Chapter2}
    \lipsum[1-5]
    \section{Section}
    \lipsum[1-5]
    
    \section{Section}
    \lipsum[1-5]
    \subsection{Subsection}
    \lipsum[1-5]
    \subsection{Subsection}
    \lipsum[1-5]
    \subsubsection{SubSubSection}
    \lipsum[1-5]
    
    \ref{chap}
    
    \begin{appendices}
        \appendix
        
        \chapter{AppChapter1}
        \lipsum[1-5]
        \section{Section1}
        \lipsum[1-5]
        
        \section{Section2}
        \lipsum[1-5]
        \subsection{Subsection1}
        \lipsum[1-5]
        \subsection{Subsection2}
        \lipsum[1-5]
        \subsubsection{SubSubSection1}
        \lipsum[1-5]
        
        \chapter{AppChapter2}
        \lipsum[1-5]
        \section{Section}
        \lipsum[1-5]
        
        \section{Section}
        \lipsum[1-5]
        \subsection{Subsection}
        \lipsum[1-5]
        \subsection{Subsection}
        \lipsum[1-5]
        \subsubsection{SubSubSection}
        \lipsum[1-5]
    \end{appendices}

    
\end{document} 

但由于我使用的是 KOMA,scrbook因此不建议这样做,因此我尝试使其与 一起使用\DeclareTOCStyleEntry,但随后我丢失了目录和各个标题之间的超链接(抱歉,此版本不再可用)。因此,我尝试使用第一个答案中的示例(将代码部分 ALTERNATIVE1 替换为 ALTERNATIVE2):

%%ALTERNATIVE2
%%BEGIN - not loosing hyperref for capital headings %https://tex.stackexchange.com/questions/586977/capitalize-headings-in-toc-using-koma-declaretocstyleentry-and-not-loosing-re/586998#586998
%\usepackage{xpatch}
\xpatchcmd{\chapterlineswithprefixformat}
{#3}
{\MakeUppercase{#3}}
{}{\PatchFailedI}

\xpatchcmd{\chapterformat}
{\chapappifchapterprefix{\nobreakspace}}
{\MakeUppercase{\chapappifchapterprefix{\nobreakspace}}}
{}{\PatchFailedII}


\xpatchcmd{\sectionlinesformat}
{#4}
{\MakeUppercase{#4}}
{}{\PatchFailedIII}

\xpatchcmd{\addtocentrydefault}
{#3}
{\MakeUppercase{#3}}
{}{\PatchFailedIV}


\pdfstringdefDisableCommands{\def\MakeUppercase#1{#1}}

%END - not loosing hyperref for capital headings

效果很好,但我仍然有以下问题:\chapter大小不正确,也没有大写,标题上的子小节也不是大写。另一个问题是目录和列表不是大写。

也许我只是没有得到你的帮助……?!??

答案1

不幸的是,问题中没有 MWE。假设您\MakeUppercase在的参数中使用\addtocentrydefault并加载包\hyperref,您将收到错误消息

! 未定义控制序列。\MakeUppercase ...ppercaseUnsupportedInPdfStrings

为了避免此错误,您可以使用\texorpdfstring

例子:

\documentclass[
  a4paper,
  10pt,
  oneside,
  chapterprefix,
  appendixprefix,
  numbers=noenddot,
  toc=chapterentrywithdots
]{scrbook}
\usepackage{blindtext}% only for dummy text

\usepackage{xpatch}
\xpatchcmd{\chapterlineswithprefixformat}
  {#3}
  {\MakeUppercase{#3}}
  {}{\PatchFailedI}
\xpatchcmd{\chapterformat}
  {\chapappifchapterprefix{\nobreakspace}}
  {\MakeUppercase{\chapappifchapterprefix{\nobreakspace}}}
  {}{\PatchFailedII}

\xpatchcmd{\sectionlinesformat}
  {#4}
  {\texorpdfstring{\MakeUppercase{#4}}{#4}}
  {}{\PatchFailedIII}

\xpatchcmd{\addtocentrydefault}
  {#3}
  {\texorpdfstring{\MakeUppercase{#3}}{#3}}
  {}{\PatchFailedIV}

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

在此处输入图片描述

或者你可以使用

\pdfstringdefDisableCommands{\def\MakeUppercase#1{#1}}

禁用\MakeUppercasepdf 书签。例如:

\documentclass[
  a4paper,
  10pt,
  oneside,
  chapterprefix,
  appendixprefix,
  numbers=noenddot,
  toc=chapterentrywithdots
]{scrbook}
\usepackage{blindtext}% only for dummy text

\usepackage{xpatch}
\xpatchcmd{\chapterlineswithprefixformat}
  {#3}
  {\MakeUppercase{#3}}
  {}{\PatchFailedI}
\xpatchcmd{\chapterformat}
  {\chapappifchapterprefix{\nobreakspace}}
  {\MakeUppercase{\chapappifchapterprefix{\nobreakspace}}}
  {}{\PatchFailedII}

\xpatchcmd{\sectionlinesformat}
  {#4}
  {\MakeUppercase{#4}}
  {}{\PatchFailedIII}

\xpatchcmd{\addtocentrydefault}
  {#3}
  {\MakeUppercase{#3}}
  {}{\PatchFailedIV}

\usepackage{hyperref}
\pdfstringdefDisableCommands{\def\MakeUppercase#1{#1}}

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

结果和上面一样。

相关内容