我当前的输出:

我当前的输出:

这实际上是一个多部分的问题,主要与使目录样式与既定样式相匹配有关。我在下面附上了 1) 我当前状态和 2) 我试图匹配的示例样式的屏幕截图。

我正在使用 KOMA-Script 来控制章节和目录,但是有些东西无法按照我希望的方式工作:

  1. 我使用的是dynnumwidth=true,但我真正想要的是章节标题与数字相邻,数字之间以某个标准长度(例如 1em)分隔。目前,动态宽度由“信息附录 A”的章节编号设置。

  2. 我还没有找到等效的dynpagenumberwidth选项,但同样,我只希望页码右对齐,并且点填充直接跨越到数字。

  3. 一般来说,有没有办法“ RedeclareTOCStyleEntry”针对特定部分子集?

  4. (优先级较低)有没有办法使点填充更紧密?

更新:我还愿意接受通过toclofttitletoc/实现相同目标的解决方案titlesec

我当前的输出:

在此处输入图片描述

示例样式:

在此处输入图片描述

最少的输入即可复制

\documentclass[
  twoside,
  fontsize=10pt,
  paper=letter]{scrartcl}
\usepackage[utf8]{inputenc}

\KOMAoptions{numbers=noenddot}
\DeclareTOCStyleEntry[indent=0em, numwidth=2.5em, pagenumberwidth=5em, beforeskip=0em,dynnumwidth=true, entryformat=\sffamily\large,pagenumberformat=\sffamily\large,linefill=\TOCLineLeaderFill]{tocline}{section}
\DeclareTOCStyleEntry[indent=1em, numwidth=2.5em, pagenumberwidth=5em, beforeskip=0em,dynnumwidth=true, entryformat=\sffamily\large,pagenumberformat=\sffamily\large,linefill=\TOCLineLeaderFill]{tocline}{subsection}
\setkomafont{section}{\sffamily\large\MakeUppercase}
\renewcommand*{\thesection}{\arabic{section}}
\setkomafont{subsection}{\normalsize\normalfont\bfseries}
\renewcommand*{\thesubsection}{\arabic{section}.\arabic{subsection}}
\setkomafont{subsubsection}{\normalsize\normalfont\bfseries}
\setkomafont{paragraph}{\normalsize\normalfont\bfseries}


\begin{document}

\setcounter{tocdepth}{2}
\renewcommand*{\contentsname}{\centering\sffamily{\large\textbf{Contents}}\par}

\tableofcontents

\clearpage
\section*{Foreword}
\addcontentsline{toc}{section}{Foreword}

\clearpage
\section{Section}

\section{Another Section}

\subsection{Subsection}

\clearpage
\appendix

\renewcommand*{\thesection}{Informative Appendix \Alph{section}\quad}
\renewcommand*{\sectionformat}{\MakeUppercase{\thesection}}
\renewcommand*{\thesubsection}{\Alph{section}\arabic{subsection}}

\section{Appendix 1}

\clearpage
\setcounter{page}{1}
\renewcommand{\thepage}{RS0001-\arabic{page}}
\renewcommand*{\thesection}{RS0001\quad}
\renewcommand*{\thesubsection}{RS0001.\arabic{subsection}\quad}

\section{Specification 0001}

\subsection{Identification and History}

\end{document}

答案1

用来\DeclareTOCStyleEntry定义新的目录条目。然后您可以重新定义\addsectiontocentry\addsubsectiontocentry在附录和规范中使用这些新的目录条目。然后dynnumwidth仍然可以使用。

\documentclass[twoside]{scrartcl}
\KOMAoptions{numbers=noenddot}
\usepackage{blindtext}% only for dummy text

\BeforeTOCHead[toc]{\renewcommand*{\raggedsection}{\centering}}% <- centered TOC heading
\setcounter{tocdepth}{\subsectiontocdepth}

% clone level, indent, numwidth of the section entry
\DeclareTOCStyleEntries[
  level:=section,
  indent:=section,
  numwidth:=section
]{tocline}{appsec,rssec}
% clone level, indent, numwidth of the subsection entry
\DeclareTOCStyleEntry[indent=1em]{tocline}{subsection}
\DeclareTOCStyleEntry[
  level:=subsection,
  indent:=subsection,
  numwidth:=subsection
]{tocline}{rssubsec}

% set dynnumwidth, pagenumberbox=\mbox etc. for all entries
\DeclareTOCStyleEntries[
  numwidth=1em,
  dynnumwidth,
  beforeskip=0em,
  entryformat=\usekomafont{tocentry},
  pagenumberformat=\usekomafont{tocentry},
  linefill=\TOCLineLeaderFill,
  pagenumberbox=\mbox
]{tocline}{section,appsec,rssec,subsection,rssubsec}

%appsec: needs colon after number
\DeclareTOCStyleEntry[
  entryformat={\def\autodot{:}\usekomafont{tocentry}}
]{tocline}{appsec}

% change the dotsep in TOC
\makeatletter
\renewcommand*{\@dotsep}{1.5}% default is 4.5
\makeatother

% font settings
\setkomafont{section}{\large}% <- changed
\setkomafont{subsection}{\normalsize\normalfont\bfseries}
\setkomafont{subsubsection}{\normalsize\normalfont\bfseries}
\setkomafont{paragraph}{\normalsize\normalfont\bfseries}
\newkomafont{tocentry}{\sffamily\large}

% uppercased section headings
\newcommand*{\originalsectionlinesformat}{}
\let\originalsectionlinesformat\sectionlinesformat
\makeatletter
\renewcommand{\sectionlinesformat}[4]{%
  \Ifstr{#1}{section}
    {\originalsectionlinesformat{#1}{#2}{#3}{\MakeUppercase{#4}}}
    {\originalsectionlinesformat{#1}{#2}{#3}{#4}}%
}

% allow a prefix for section numbers (needed in appendix)
\newcommand*{\sectionprefix}{}
\newcommand*{\originalsectionformat}{}
\let\originalsectionformat\sectionformat
\renewcommand*{\sectionformat}{%
  \Ifstr{\sectionprefix}{}
    {\originalsectionformat}
    {\MakeUppercase{\sectionprefix}\thesection:\enskip}%
}

\newcommand*\appendixmore{%
  \clearpage
  \renewcommand*{\sectionprefix}{Informative Appendix~}%
  \renewcommand*{\addsectiontocentry}[2]{%
    \addtocentrydefault{appsec}{\sectionprefix##1}{##2}%
  }
}

\newcommand*{\preinitsectionhook}[1]{}
\AddtoDoHook{heading/preinit/section}{\preinitsectionhook}
\newcommand*{\RS}{%
  \setcounter{section}{0}
  \renewcommand*{\sectionprefix}{}%
  \renewcommand*{\thesection}{RS%
    \ifnum\value{section}<1000 0\fi
    \ifnum\value{section}<100 0\fi
    \ifnum\value{section}<10 0\fi
    \arabic{section}%
  }%
  \renewcommand*{\preinitsectionhook}[1]{%
    \cleardoubleoddpage% <- odd page numbers must be on right pages!!
    \setcounter{page}{1}%
    \renewcommand{\thepage}{\thesection-\arabic{page}}%
  }%
  \renewcommand*{\addsectiontocentry}[2]{%
    \addtocentrydefault{rssec}{##1}{##2}%
  }%
  \renewcommand*{\addsubsectiontocentry}[2]{%
    \addtocentrydefault{rssubsec}{##1}{##2}%
  }%
}

\begin{document}
\tableofcontents

\clearpage
\addsec{Foreword}% <- changed
\Blindtext
\clearpage
\blinddocument
\blinddocument

\appendix
\section{Appendix 1}
\subsection{Subappendix 1}
\Blindtext
\section{Appendix 2}
\blindtext
\subsection{Another Subappendix}
\Blindtext

\RS
\section{Specification 0001}
\subsection{Identification and History}
\Blindtext
\subsection{More infos}
\Blindtext

\section{Specification 0002}
\subsection{Identification and History}
\Blindtext[30]
\subsection{More infos}
\Blindtext
\end{document}

在此处输入图片描述

补充说明:

  1. 如果更改双面文档中的页码值,请确保奇数页码位于右页。因此,请在 之前使用\cleardoubleoddpage(或至少\cleardoublepage\setcounter{page}{1}
  2. 不要在或\MakeUppercase的参数中使用,因为它不是字体命令。\setkomafont\addtokomafont
  3. 在 的定义中不要使用 format ( \centering) 或 font ( ) 命令。\sffamily\contentsname
  4. \usepackage[utf8]{inputenc}仅适用于旧的 TeX 发行版。

答案2

以下是我根据您的最少输入和示例样式图像得出的结论:

在此处输入图片描述

这可能不是最优雅的方式,但我希望它能满足您的需求。您所要做的就是使用和document切换内容类型\appendices\specifications

代码

\documentclass[twoside]{scrartcl}

\KOMAoptions{numbers=noenddot}

% Only needed for demonstration
    \usepackage{blindtext} 

% The TOC entries (almost) like you defined them
    \DeclareTOCStyleEntry[%
        indent=0em,%
        numwidth=1em,%
        pagenumberwidth=1em,%
        beforeskip=0em,%
        entryformat=\sffamily\large,%
        pagenumberformat=\sffamily\large,%
        linefill=\TOCLineLeaderFill
    ]{tocline}{section}
    
    \DeclareTOCStyleEntry[%
        indent=1em,%
        numwidth=2em,%
        pagenumberwidth=1em,%
        beforeskip=0em,%
        entryformat=\sffamily\large,%
        pagenumberformat=\sffamily\large
    ]{tocline}{subsection}

% Tight dots
    \makeatletter
        \renewcommand\@dotsep{.}
    \makeatother

% Your headings untouched
    \setkomafont{section}{\sffamily\large\MakeUppercase}
        \renewcommand*{\thesection}{\arabic{section}}
    \setkomafont{subsection}{\normalsize\normalfont\bfseries}
        \renewcommand*{\thesubsection}{\arabic{section}.\arabic{subsection}}
    \setkomafont{subsubsection}{\normalsize\normalfont\bfseries}
    \setkomafont{paragraph}{\normalsize\normalfont\bfseries}


% Switch command for appendix, similar to \frontmatter, \mainmatter, etc.
    \newcommand{\appendices}{%
        \clearpage\appendix
            
        \renewcommand*{\thesection}{Informative Appendix \Alph{section}:}
        \renewcommand*{\sectionformat}{\MakeUppercase{\thesection}\enskip}
        \renewcommand*{\thesubsection}{\Alph{section}\arabic{subsection}}
        
        \addtocontents{toc}{%
            \DeclareTOCStyleEntry[dynnumwidth]{tocline}{section}}
    }

% Switch command for the specifications
    \newcommand{\specifications}{%
        \clearpage\appendix
        \setcounter{page}{1}
    
        \renewcommand*{\thesection}{RS%
            \ifnum\value{section}<1000 0\fi%
            \ifnum\value{section}<100 0\fi%
            \ifnum\value{section}<10 0\fi%
            \arabic{section}}
        \renewcommand{\thepage}{\thesection-\arabic{page}}
        \renewcommand*{\thesubsection}{\thesection.\arabic{subsection}}
        
        \addtocontents{toc}{%
            \DeclareTOCStyleEntry[dynnumwidth=false,numwidth=4em,pagenumberwidth=4.5em]{tocline}{section}
            \DeclareTOCStyleEntry[numwidth=5em,pagenumberwidth=4.5em]{tocline}{subsection}}
    }


\begin{document}

%   The TOC
    \setcounter{tocdepth}{2}
    \renewcommand*{\contentsname}{\centering\sffamily{\large\textbf{Contents}}\par}
    \tableofcontents
    \clearpage
    
%   This is a shorter version for your \section*{Foreword}\addcontentsline{toc}{section}{Foreword}  
    \addsec{Foreword}
    \clearpage
    
%   Filling up the TOC
    \blinddocument
    \blinddocument
    
\appendices
    
    \section{An Appendix}
    \clearpage
    
    \section{Another Appendix}  

\specifications
    
    \section{Liquid-Cooled Chiller} 
    \subsection{Identification and History}
    \clearpage
    
    \section{Specification 0002}
    
\end{document}

相关内容