乳胶参考中的自定义小节编号

问题描述 投票:0回答:1

我试图使用自己的计数器并为自定义节名称命名\ subsubsection,但对\ ref没有影响。

\newcounter{strategyCounter}
\titleformat{\subsubsection} [hang] 
    {\normalsize\bfseries\sffamily} 
    {Strategy\stepcounter{strategyCounter}\thestrategyCounter}
    {1em}{}
...
\subsubsection{Foo}\label{foo}
...
\subsubsection{Bar}\label{bar}
...
see \ref{foo} // output: 1.1.1.1; expected: Strategy 1
see \nameref{foo} // output: Foo; expected: Foo

有人有想法吗?

latex xelatex
1个回答
0
投票

如果您覆盖处理\subsubsection的通常方式,则将完成以下工作:

enter image description here

\documentclass{report}

\usepackage{titlesec,hyperref}

\setcounter{secnumdepth}{3}

\titleformat{\subsubsection}% <command>
  [hang]% <shape>
  {\normalsize\bfseries\sffamily}% <format>
  {\thesubsubsection}% <label>
  {1em}% <sep>
  {}% <before-code>

\renewcommand{\thesubsubsection}{Strategy \arabic{subsubsection}}

\newcommand{\strategy}{\subsubsection}

\begin{document}

\chapter{A chapter}
\section{A section}
\subsection{A subsection}

\strategy{Foo}\label{foo}

\strategy{Bar}\label{bar}

See \ref{foo}.% output: Strategy 1

See \nameref{foo}.% output: Foo

\end{document}

对于语义,我定义了\strategy来调用\subsubsection(因此它们基本上是相同的)。它使您的代码更加清晰。

© www.soinside.com 2019 - 2024. All rights reserved.