隐藏目录中的附录标题/章节标题时目录列表前缀的问题

隐藏目录中的附录标题/章节标题时目录列表前缀的问题

请查看提供的最小示例。我尝试实现以下三件事:

  1. 在方程列表中的每个条目中添加“方程”作为前缀
  2. 为 SpecialAlgorithms 列表中的每个条目添加“SpecialAlgorithm”作为前缀

names要求 1 应该通过在语句中设置属性来解决\DeclareNewTOC[..]{equ},但这不起作用。

\addtocontents{loa}{\def\string\figurename{SpecialAlgorithm}}需求 3 应该通过在命令后直接设置来解决\listofalgorithms,但每个算法都以前缀“Fig.”显示。我不知道为什么它使用图形的自定义前缀。

请支持我,我自己无法解决这个问题。我感谢每一个帮助和建议。谢谢!

\documentclass[
  paper=a4,
  fontsize=12pt,
  twoside=false,
  open=right,
  numbers=noenddot,
  listof=nochaptergap,
  listof=totoc,% lists in toc
  %toc=sectionentrywithdots,
  ]{scrbook}
\usepackage[utf8]{inputenc}
\usepackage{microtype}
\usepackage[ngerman,english]{babel}
\usepackage[pdftex]{graphicx}  
\usepackage[final]{listings}  
\usepackage[intoc]{nomencl}

\setkomafont{sectioning}{\normalcolor\bfseries}
\renewcommand*{\chapterheadstartvskip}{\vspace*{0pt}} 
\renewcommand*{\chapterheadendvskip}{\vspace*{15pt}} 

% HEADER SEPERATION LINE
\usepackage[headsepline,footsepline]{scrlayer-scrpage}

\usepackage{chngcntr}  % Counter für durchgängige Nummerierung 
\counterwithout{figure}{chapter}
\counterwithout{table}{chapter}
\counterwithout{equation}{chapter}

\usepackage[titles]{tocloft}   
\renewcommand{\cftsecleader}{\cftdotfill{\cftdotsep}}

\usepackage{algorithm}
\usepackage{algpseudocode}
\renewcommand{\listofalgorithms}{ 
    \begingroup 
    \listof{algorithm}{SpecialAlgorithm} 
    \endgroup 
}
\setlength{\cftfignumwidth}{2cm}                     
\setlength{\cfttabnumwidth}{2cm}                                           
\setlength{\cftfigindent}{0cm}                                                     
\setlength{\cfttabindent}{0cm} 

\usepackage[justification=centering,labelfont=bf]{caption} 
\usepackage{booktabs, tabularx}
\usepackage{ltablex}

\renewcommand{\cftfigpresnum}{Fig. }
\renewcommand{\cfttabpresnum}{Tab. }  

\BeforeStartingTOC[lof]{\def\autodot{:}}
\BeforeStartingTOC[lot]{\def\autodot{:}}

\DeclareNewTOC[ 
type=equation, 
name={Equationl}, 
types=equations, 
listname={List of equations}, 
forcenames
]{equ} 
\newcommand{\equationentry}[2][\theequation]{% 
    \addxcontentsline{equ}{equation}[{#1}]{#2}% 
} 
\BeforeStartingTOC[equ]{\def\autodot{:}} 

\usepackage{scrhack} 
\makeatletter
\def\l@lstlisting#1#2{\@dottedtocline{1}{0em}{1em}{\hspace{1,5em} Lst. #1}{#2}}
\@removefromreset{footnote}{chapter}
\newenvironment{megaalgorithm}[1][htb]{%
    \renewcommand{\ALG@name}{SpecialAlgorithm}% Update algorithm name
    \begin{algorithm}[#1]%
    }{\end{algorithm}}
\makeatother

\setlength{\cftbeforechapskip}{0.2cm}

\begin{document}
    % CHOOSE "ngerman" or "english"
    \selectlanguage{ngerman}

    \frontmatter  % ROMAN NUMBERING
    \pagenumbering{Roman}              

    \tableofcontents
    \listoffigures
    \listoftables
    \addcontentsline{toc}{chapter}{List of SpecialAlgorithms}
    \listofalgorithms
    \addtocontents{loa}{\def\string\figurename{SpecialAlgorithm}}
    \listofequations

    \mainmatter % ARABIC NUMBERING            

    \chapter{Test}
    \section{Test 1}
    \chapter{Test 2}

    \begin{tabularx}{\textwidth}{p{5cm}|*{1}{X}}
        \caption[Table1]{Table1} \\
        \label{tab:table1}
        %\toprule
        column & column \\
        \midrule
        \endfirsthead
        \toprule
        column & column \\
        \midrule
        \endhead
        column & column \\
        \addlinespace
        %\bottomrule 
    \end{tabularx}

    \begin{equation}\label{eq:Eq1}
    N_{v} = N_{r}
    \equationentry{Berechnung der Anzahl der Werte einer Partition} 
    \end{equation}

    \begin{megaalgorithm}[H]\small
        \caption[Example-Algorithm]{Example-Algorithm}
        \label{algo:Worker-Thread}
        \begin{algorithmic}[1]
            \For{i in range}
            \State print(i) 
            \EndFor
        \end{algorithmic}
    \end{megaalgorithm}

   \appendix
    \chapter*{Appendix}
    \phantomsection
    %\addcontentsline{toc}{section}{Anhang}
    %\addtocontents{toc}{\vspace{-0.5em}}
    \addcontentsline{toc}{chapter}{\appendixname} 
    \addtocontents{toc}{\protect\value{tocdepth}=0}

    \renewcommand{\thesection}{\Roman{section}}

    \section{Apendix Test}
    \subsection{Apendix Test 1}

\end{document}

更新:以前的要求 1:隐藏附录的章节和章节已通过\addtocontents{toc}{\protect\value{tocdepth}=0}在 \appendix 命令后直接使用解决。

答案1

不要将该包tocloft与 KOMA-Script 类一起使用。

\documentclass[
  paper=a4,
  fontsize=12pt,
  twoside=false,
  open=right,
  numbers=noenddot,
  listof=nochaptergap,
  listof=totoc,% lists in toc
  listof=entryprefix,% <- added
  captions=tableheading,% <- added
  ]{scrbook}

\usepackage{blindtext}% only for dummy text

\usepackage[utf8]{inputenc}
\usepackage{microtype}
\usepackage[main=ngerman,english]{babel}
\usepackage{graphicx}% <- option removed
\usepackage[final]{listings}
\usepackage[intoc]{nomencl}

\setkomafont{sectioning}{\normalcolor\bfseries}

\RedeclareSectionCommand[
  beforeskip=-1sp,% <- skip before chapter titles
  afterskip=15pt,% <- skip after chapter titles
  tocbeforeskip=0.2cm% <- skip before chapter entries in TOC
]{chapter}

\usepackage[headsepline,footsepline,
  automark% <- added
]{scrlayer-scrpage}

\usepackage{chngcntr}
\counterwithout{figure}{chapter}
\counterwithout{table}{chapter}
\counterwithout{equation}{chapter}
\counterwithout*{footnote}{chapter}

\usepackage{booktabs}
\usepackage{ltablex}% loads also tabularx
\usepackage[justification=centering,labelfont=bf]{caption}

\providecaptionname{ngerman}{\listoflofentryname}{Abb.}
\providecaptionname{ngerman}{\listoflotentryname}{Tab.}

\AtBeginDocument{%
  \doforeachtocfile[float]{\BeforeStartingTOC[#1]{\def\autodot{:}}}%
}

\usepackage{algorithm}
\usepackage{algpseudocode}

\addtotoclist[float]{loa}
\renewcommand\listofalgorithms{\listoftoc[{List of SpecialAlgorithms}]{loa}}
\DeclareTOCStyleEntry[
  level=1,
  indent=0pt,
  numwidth=2.3em
]{tocline}{algorithm}
\providecaptionname{english}{\listofloaentryname}{SpecialAlgorithm}
\providecaptionname{ngerman}{\listofloaentryname}{SpecialAlgorithm}

\DeclareNewTOC[ 
  type=equation, 
  name={Equation}, 
  types=equations, 
  listname={List of equations}
]{equ} 
\newcommand{\equationentry}[2][\theequation]{% 
    \addxcontentsline{equ}{equation}[{#1}]{#2}% 
}

\makeatletter
\newenvironment{megaalgorithm}[1][htb]{%
  \renewcommand{\ALG@name}{SpecialAlgorithm}% Update algorithm name
  \begin{algorithm}[#1]%
  }
  {\end{algorithm}}
\makeatother

%\usepackage{hyperref}

\begin{document}
\frontmatter  % ROMAN NUMBERING
\pagenumbering{Roman}

\tableofcontents
\listoffigures
\listoftables
\listofalgorithms
\listofequations

\mainmatter % ARABIC NUMBERING            
\blinddocument
\begin{tabularx}{\textwidth}{p{5cm}|*{1}{X}}
  \caption[Table1]{Table1} \\
  \label{tab:table1}
  %\toprule
  column & column \\
  \midrule
  \endfirsthead
  \toprule
  column & column \\
  \midrule
  \endhead
  column & column \\
  \addlinespace
  %\bottomrule 
\end{tabularx}

\begin{equation}\label{eq:Eq1}
  N_{v} = N_{r}
  \equationentry{Berechnung der Anzahl der Werte einer Partition} 
\end{equation}

\begin{megaalgorithm}[H]\small
  \caption[Example-Algorithm]{Example-Algorithm}
  \label{algo:Worker-Thread}
  \begin{algorithmic}[1]
    \For{i in range}
    \State print(i) 
    \EndFor
  \end{algorithmic}
\end{megaalgorithm}

\blinddocument

\appendix
\addchap{Appendix}
\addtocontents{toc}{\protect\value{tocdepth}=0}
\renewcommand{\thesection}{\Roman{section}}

\section{Apendix Test}
\subsection{Apendix Test 1}
\end{document}

运行三次即可获得

在此处输入图片描述

相关内容