自定义部分标题中的分隔符

自定义部分标题中的分隔符

我已经通过 定义了自定义部分命令,\DeclareNewSectionCommand并通过 为其赋予了自定义装备\renewcommand\thecustomsection{Custom Section \arabic{customsection}。使用\customsection{Blah}结果当然是这样的:

Custom Section 1 Blah

然而我希望它看起来像是:

Custom Section 1 - Blah

中间有一个自定义分隔符。

我已经通过在行中添加分隔符实现了这一点\renewcommand,但这样分隔符也会出现在\autoref对此类自定义部分的引用中,例如:

In \autoref{csec:blah} lorem ipsum\dots

结果是:

In Custom Section 1 - lorem ipsum...

那么,如何在公共标题部分“自定义部分 X”和实际部分标题之间添加分隔符,而不会让它出现在 refs 和其他类似情况下,其中只使用部分标题的公共部分?

梅威瑟:

\documentclass{scrartcl}
\usepackage{hyperref}
\setlength{\parindent}{0mm}
\setlength{\parskip}{6mm}

% Declare the new section command customsection
\DeclareNewSectionCommand[
    afterskip=1.5ex plus .2ex,
    beforeskip=-3.25ex plus -1ex minus -.2ex,
    indent=0pt,
    level=2,
    font=\usekomafont{subsection},
    tocindent=1.5em,
    tocnumwidth=2.3em,
    counterwithin=section,
    style=section]{customsection}

% Here I add the hyphen as a custom delimiter 
% between the prefix and the title.
% This is obviously the wrong way to do it. 
\renewcommand{\thecustomsection}{Custom Section \arabic{customsection} - }


\begin{document}

\section{Hello}
\customsection{Blah}\label{csec:blah}
% What it looks like: 
% Custom Section 1 -  Blah

% What it should look like: 
% Custom Section 1 - Blah

% As you can see, the delimiter is also 
% not centered between the prefix and 
% the actual section title.

\customsection{Blubb}\label{csec:blubb}
In \autoref{csec:blah} lorem ipsum...
% What it looks like:
% In Custom Section 1 -  lorem ipsum...

% What it should look like:
% In Custom Section 1 lorem ipsum...

\end{document}

答案1

\customsectionformat更改创建标题时所使用的定义。

\documentclass[]{scrartcl}

\usepackage[]{hyperref}
% Declare the new section command customsection
\DeclareNewSectionCommand[
    afterskip=1.5ex plus .2ex,
    beforeskip=-3.25ex plus -1ex minus -.2ex,
    indent=0pt,
    level=2,
    font=\usekomafont{subsection},
    tocindent=1.5em,
    tocnumwidth=2.3em,
    counterwithin=section,
    style=section]{customsection}

\renewcommand*\thecustomsection{Custom Section~\arabic{customsection}}
\renewcommand*\customsectionformat{\thecustomsection\ -\ }

\begin{document}
\section{Hello}
\customsection{Blah}\label{csec:blah}
% What it looks like: 
% Custom Section 1 -  Blah

% What it should look like: 
% Custom Section 1 - Blah

% As you can see, the delimiter is also 
% not centered between the prefix and 
% the actual section title.

\customsection{Blubb}\label{csec:blubb}
In \autoref{csec:blah} lorem ipsum...
% What it looks like:
% In Custom Section 1 -  lorem ipsum...

% What it should look like:
% In Custom Section 1 lorem ipsum...

\end{document}

在此处输入图片描述

相关内容