scrartcl 目录中的大写字母、斜体和超链接,不使用 tocstyle

scrartcl 目录中的大写字母、斜体和超链接,不使用 tocstyle

我的文档中的目录目前如下所示: 在此处输入图片描述

它看起来应该是这样的(带有超链接)——但是有一个问题。我使用包才得到这个结果tocstyle,现在我想改变它。相反,如果可能的话,我想使用包得到相同的结果tocloft。这是我到目前为止使用的代码,所以这个仍然包含tocstyle

\documentclass[headings=normal, oneside, hidelinks]{scrartcl}

\usepackage{tocstyle}  
\usetocstyle{allwithdot} 
\setcounter{secnumdepth}{4}
\setcounter{tocdepth}{4} 

%% Distances between number and entry
\settocfeature[toc][1]{spaceafternumber}{15pt}
\settocfeature[toc][2]{spaceafternumber}{15pt}
\settocfeature[toc][3]{spaceafternumber}{12pt}
\settocfeature[toc][4]{spaceafternumber}{12pt}

%% Formatting entries
\usepackage{microtype}
\settocfeature[toc][1]{entryhook}{\MakeHyperLinkStartUppercase\bfseries} 
\settocfeature[toc][2]{entryhook}{\MakeHyperLinkStartUppercase}
\settocfeature[toc][3]{entryhook}{\itshape} 
\settocfeature[toc][4]{entryhook}{}

%% Entries with uppercase and hyperlinks
\makeatletter 
\newcommand*\MakeHyperLinkStartUppercase{% 
\let\saved@hyper@linkstart\hyper@linkstart 
\def\hyper@linkstart##1##2##3{% 
    \saved@hyper@linkstart{##1}{##2}{\textls[50]{\MakeUppercase {##3}}}}% 
} 
\makeatother 

\usepackage{hyperref}

\begin{document} 
\tableofcontents
\newpage

\section{Eins}
\section{Zwei}
\subsection{Zwei}
\section{Drei}
\subsection{Drei}
\subsubsection{Drei}
\section{Vier}
\subsection{Vier}
\subsubsection{Vier}
\paragraph{Vier}
\end{document}

我一直在寻找替代解决方案,但大多数建议都包含回忆录类。不过,我能够从这个答案中得到一些帮助(如何使目录中的章节名称大写?)。以下是我尝试使用时取得的进展tocloft

 \documentclass[headings=normal, oneside, hidelinks]{scrartcl}

 \usepackage{tocloft}
 \usepackage{textcase}
 \setcounter{tocdepth}{4} 
 \setcounter{secnumdepth}{4}

 %% Distances between dots
 \makeatletter
 \renewcommand*{\@dotsep}{0.5}
 \makeatother

 %% Distances between number and entry
 \makeatletter
 \renewcommand{\l@section}{\vspace{.025\textwidth} \@dottedtocline{1}{20pt}{20pt}}
 \renewcommand{\l@subsection}{\@dottedtocline{2}{40pt}{30pt}}
 \renewcommand{\l@subsubsection}{\@dottedtocline{3}{70pt}{40pt}}
 \renewcommand{\l@paragraph}{\@dottedtocline{4}{110pt}{40pt}}

 \usepackage{hyperref} 

 %% Uppercase and hyperref for sections
 \makeatletter
 \let\oldcontentsline\contentsline
 \def\contentsline#1#2{%
\expandafter\ifx\csname l@#1\endcsname\l@section
\expandafter\@firstoftwo
\else
\expandafter\@secondoftwo
\fi
{%
    \oldcontentsline{#1}{\bfseries\MakeTextUppercase{#2}}%
}{%
\oldcontentsline{#1}{#2}%
 }%
 }
 \makeatother


 \begin{document} 
\tableofcontents
\newpage

\section{Eins}
\section{Zwei}
\subsection{Zwei}
\section{Drei}
\subsection{Drei}
\subsubsection{Drei}
\section{Vier}
\subsection{Vier}
\subsubsection{Vier}
\paragraph{Vier}
 \end{document}

所以基本上我仍然需要将小节用大写,而小节用斜体... 有人知道如何实现这一点吗? 提前谢谢您!

答案1

tocloft请注意,不建议与 KOMA-Script 类一起使用。

使用下一个 KOMA-Script 版本 3.20,无需额外的软件包即可获得所需的结果。您可以从 KOMA-Script 网站获取预发布版本:使用最新的 KOMA-Script 和 TeX Live、MacTeX 或 MiKTeX

\documentclass[headings=normal, hidelinks]{scrartcl}[2016/03/16]
\usepackage{blindtext}% dummy text
\setcounter{secnumdepth}{4}
\setcounter{tocdepth}{4} 

\RedeclareSectionCommand[
  tocnumsep=15pt,
  toclinefill=\TOCLineLeaderFill,
  tocpagenumberformat=\normalfont
]{section}
\RedeclareSectionCommand[tocnumsep=15pt]{subsection}
\RedeclareSectionCommand[tocentryformat=\itshape,tocnumsep=12pt]{subsubsection}
\RedeclareSectionCommand[tocnumsep=12pt]{paragraph}

\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
\newpage

\section{Eins}
\section{Zwei}
\subsection{Zwei}
\section{Drei}
\subsection{Drei}
\subsubsection{Drei}
\section{Vier}
\subsection{Vier}
\subsubsection{Vier}
\paragraph{Vier}
\blinddocument
\blinddocument
\end{document}

在此处输入图片描述


对于 KOMA-Script 版本 3.19a(CTAN 上的最新版本)或更早版本,我强烈建议使用tocstyletocstyle和 KOMA-Script 类的作者相同。由于 alpha 版本而产生的警告可以忽略。

\documentclass[headings=normal, oneside, hidelinks]{scrartcl}
\usepackage{blindtext}% dummy text

\usepackage{tocstyle}
\usetocstyle{allwithdot} 
\setcounter{secnumdepth}{4}
\setcounter{tocdepth}{4} 

%Distances between number and entry
\settocfeature[toc][1]{spaceafternumber}{15pt}
\settocfeature[toc][2]{spaceafternumber}{15pt}
\settocfeature[toc][3]{spaceafternumber}{12pt}
\settocfeature[toc][4]{spaceafternumber}{12pt}

%Formatting entries
\usepackage{microtype}
\settocfeature[toc][1]{entryhook}{\bfseries} 
\settocfeature[toc][3]{entryhook}{\itshape} 
\settocfeature[toc][4]{entryhook}{}

\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
\newpage

\section{Eins}
\section{Zwei}
\subsection{Zwei}
\section{Drei}
\subsection{Drei}
\subsubsection{Drei}
\section{Vier}
\subsection{Vier}
\subsubsection{Vier}
\paragraph{Vier}
\blinddocument
\blinddocument
\end{document}

如果您确实想使用,tocloft您也可以重新定义\addsectiontocentry等等。

\documentclass[headings=normal, oneside, hidelinks]{scrartcl}
\usepackage{blindtext}% dummy text

\usepackage{tocloft}
\setcounter{tocdepth}{4} 
\setcounter{secnumdepth}{4}

%% Distances between dots
\makeatletter
\renewcommand*{\@dotsep}{0.5}
\makeatother

%% Distances between number and entry
\makeatletter
\renewcommand{\l@section}{\vspace{.025\textwidth} \@dottedtocline{1}{20pt}{20pt}}
\renewcommand{\l@subsection}{\@dottedtocline{2}{40pt}{30pt}}
\renewcommand{\l@subsubsection}{\@dottedtocline{3}{70pt}{40pt}}
\renewcommand{\l@paragraph}{\@dottedtocline{4}{110pt}{40pt}}

\usepackage{hyperref} 

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

\begin{document} 
\tableofcontents
\newpage

\section{Eins}
\section{Zwei}
\subsection{Zwei}
\section{Drei}
\subsection{Drei}
\subsubsection{Drei}
\section{Vier}
\subsection{Vier}
\subsubsection{Vier}
\paragraph{Vier}
\blinddocument
\blinddocument
\end{document}

在此处输入图片描述

相关内容