我尝试使用自己的计数器并将 \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
有人有想法吗?
答案1
如果您要覆盖通常的处理方式\subsubsection
,则以下方法有效:
\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
(因此它们基本相同)。它可使您的代码更加清晰。