自定义目录中的章节

自定义目录中的章节

社区,

我之前在这个平台上得到过很多次很大的帮助,我真的希望你能再次帮助我!我正在尝试自定义目录,以便像图片列表和表格列表这样的内容:1.出现在目录中 2.用草书书写 3.各节尽可能靠近小节/小节不缩进

前两点我可以做到,但最后一点却行不通:

\documentclass[paper=a4,12pt,numbers=endperiod]{scrartcl}
\usepackage{fontspec}
\setmainfont[SmallCapsFont={* Caps}]{Latin Modern Roman}
\usepackage{polyglossia}
\setdefaultlanguage{english}
\usepackage[autostyle=true]{csquotes}
\usepackage{yfonts}
\usepackage{xltxtra}
\usepackage{graphicx}
\usepackage{float}
\usepackage{caption}
\usepackage[english]{fancyref}
\usepackage{tocbasic}
\KOMAoptions{toc=sectionentrydotfill}

\begin{document}
\newpage
\thispagestyle{empty}
\tableofcontents
\newpage
\listof{table}{\textit{List of Tables}}
\addcontentsline{toc}{section}{\textit{List of Tables}}
\section*{\textit{List of Abbreviations}}
    \addcontentsline{toc}{section}{\textit{List of Abbreviations}}
\section{Test}
Text
\section{Test2}
Text2
\end{document}
\section*{\textit{Glossary}}
    \addcontentsline{toc}{section}{\textit{Glossary}}
 \section*{\textit{Declaration of Originality}}
    \addcontentsline{toc}{section}{\textit{Declaration of Originality}}

我找到了一个允许您自定义目录的包,但我无法真正使用它,而且它总是产生错误。我认为最简单的方法是定义一个新的部分类别(如“nsection”),该类别具有与正常部分不同的基线跳过(因为我非常想保留它)

非常感谢!如果您需要更多信息,请告诉我!

编辑:我添加了更多在 LaTex 中不属于其自身功能的“随机”部分,以证明我希望能够将“nsection”用于我想要的任何东西

答案1

更新(所讨论的 MWE 和期望结果已更改:使用nsection不限于 LOF 和 LOT 等列表)

\documentclass[paper=a4,12pt,numbers=endperiod]{scrartcl}% loads and uses tocbasic!
\usepackage{xltxtra}% loads also fontspec
\setmainfont[SmallCapsFont={* Caps}]{Latin Modern Roman}
\usepackage{polyglossia}
\setdefaultlanguage{english}
\usepackage[autostyle=true]{csquotes}
\usepackage{yfonts}
\usepackage{graphicx}
%\usepackage{float}
\usepackage{caption}
\usepackage[english]{fancyref}

\KOMAoptions{
  toc=sectionentrydotfill,
  listof=totoc
}

\newkomafont{standardsection}{\Large}
\newkomafont{nsection}{\usekomafont{standardsection}\slshape}

\DeclareTOCStyleEntry[%
  level=\sectiontocdepth,%
  beforeskip=0pt plus .2pt,%
  indent=0pt,%
  numwidth=1.5em,%
  entryformat=\usekomafont{sectionentry}\textsl%
]{section}{nsection}

\newcommand*\usensection{% define switch to nsection
  \addtocontents{toc}{\protect\addvspace{1em plus 1pt}}% additional space in TOC before the first nsection entry
  \setkomafont{section}{\usekomafont{nsection}}%
  \renewcommand\addsectiontocentry[2]{\addtocentrydefault{nsection}{##1}{##2}}%
}
\newcommand*\usestandardsection{% define switch to standard section
  \setkomafont{section}{\usekomafont{standardsection}}%
  \renewcommand\addsectiontocentry[2]{\addtocentrydefault{section}{##1}{##2}}%
}

\AfterTOCHead[toc]{\thispagestyle{empty}\pagestyle{empty}}
\AfterStartingTOC[toc]{\clearpage}

\begin{document}
\tableofcontents

\usensection% switch to nsection
\listoftables
\listoffigures
\addsec{List of Abbreviations}

\usestandardsection% switch to standard section
\section{Test}
Text
\section{Test2}
Text2

\usensection% switch to nsection
\addsec{Glossary}
\addsec{Declaration of Originality}

\end{document}

结果:

在此处输入图片描述


原始答案nsection仅适用于 LOF 和 LOT 等列表)

这里建议nsection对 TOC 中的 LOF 和 LOT 条目使用新声明的 TOCStyleEntry。因此\addsectiontocentry在本地重新定义。

请注意,KOMA-Script 类srcartcl已加载包tocbasic。因此,无需再次加载。

\documentclass[paper=a4,12pt,numbers=endperiod]{scrartcl}% loads and uses tocbasic!
\usepackage{xltxtra}% loads also fontspec
\setmainfont[SmallCapsFont={* Caps}]{Latin Modern Roman}
\usepackage{polyglossia}
\setdefaultlanguage{english}
\usepackage[autostyle=true]{csquotes}
\usepackage{yfonts}
\usepackage{graphicx}
%\usepackage{float}
\usepackage{caption}
\usepackage[english]{fancyref}

\KOMAoptions{
  toc=sectionentrydotfill,
  listof=totoc
}

\DeclareTOCStyleEntry[%
  level=\sectiontocdepth,%
  beforeskip=0pt plus .2pt,%
  indent=0pt,%
  numwidth=1.5em,%
  entryformat=\usekomafont{sectionentry}\textsl%
]{section}{nsection}
\BeforeTOCHead{%
  \addtokomafont{section}{\slshape}%
  \renewcommand\addsectiontocentry[2]{\addtocentrydefault{nsection}{#1}{#2}}%
}

\AfterTOCHead[toc]{\thispagestyle{empty}\pagestyle{empty}}
\AfterStartingTOC[toc]{\clearpage}

\begin{document}
\tableofcontents
\listoftables
\listoffigures
\section{Test}
Text
\section{Test2}
Text2
\end{document}

结果:

在此处输入图片描述


如果更改应仅限于带有owner=float(LOT,LOF 等)的列表,则可以使用:

\makeatletter
\doforeachtocfile[float]{% do for all lists with owner=float like LOF and LOT
  \BeforeTOCHead[\@currext]{%
    \addtokomafont{section}{\slshape}%
    \renewcommand\addsectiontocentry[2]{\addtocentrydefault{nsection}{##1}{##2}}%
  }%
}
\makeatother

在此处输入图片描述

代码:

\documentclass[paper=a4,12pt,numbers=endperiod]{scrartcl}% loads and uses tocbasic!
\usepackage{xltxtra}% loads also fontspec
\setmainfont[SmallCapsFont={* Caps}]{Latin Modern Roman}
\usepackage{polyglossia}
\setdefaultlanguage{english}
\usepackage[autostyle=true]{csquotes}
\usepackage{yfonts}
\usepackage{graphicx}
%\usepackage{float}
\usepackage{caption}
\usepackage[english]{fancyref}

\KOMAoptions{
  toc=sectionentrydotfill,
  listof=totoc
}

\DeclareTOCStyleEntry[%
  level=\sectiontocdepth,%
  beforeskip=0pt plus .2pt,%
  indent=0pt,%
  numwidth=1.5em,%
  entryformat=\usekomafont{sectionentry}\textsl%
]{section}{nsection}
\makeatletter
\doforeachtocfile[float]{% do for all lists with owner=float like LOF and LOT
  \BeforeTOCHead[\@currext]{%
    \addtokomafont{section}{\slshape}%
    \renewcommand\addsectiontocentry[2]{\addtocentrydefault{nsection}{##1}{##2}}%
  }%
}
\makeatother

\AfterTOCHead[toc]{\thispagestyle{empty}\pagestyle{empty}}
\AfterStartingTOC[toc]{\clearpage}

\begin{document}
\tableofcontents
\listoftables
\listoffigures
\section{Test}
Text
\section{Test2}
Text2
\end{document}

请注意,使用以下命令可获得相同的结果

\BeforeTOCHead[lof]{%
  \addtokomafont{section}{\slshape}%
  \renewcommand\addsectiontocentry[2]{\addtocentrydefault{nsection}{#1}{#2}}%
}
\BeforeTOCHead[lot]{%
  \addtokomafont{section}{\slshape}%
  \renewcommand\addsectiontocentry[2]{\addtocentrydefault{nsection}{#1}{#2}}%
}

相关内容