hyperref using ref: 如何避免章节编号

hyperref using ref: 如何避免章节编号
perf~\ref{soft_reset_perf}

\phantomsection
\item[perf]:~\label{soft_reset_perf} Indicates that a soft reset has been performed.

它在“perf”旁边显示部分编号。我怎样才能获得没有部分编号的链接?

~\nameref{soft_reset_perf}得到了定义标签的部分的名称。我希望显示项目名称(本例中为“perf”)而不是部分名称。

答案1

这是实现输出的另一种方法。由于您要引用标签的名称,因此使用分段单元是理想的选择。

在下面的例子中,我已将其定义\Item为类似于\paragraph(它被设置为“段落级别”,并进行了一些间距调整),因为它现在是一个分段单元。因此,使用\label{<lab>}\nameref{<lab>}可以按预期工作:

在此处输入图片描述

\documentclass{article}
\usepackage{nameref}% http://ctan.org/pkg/nameref
\makeatletter
\newcommand\Item{\@startsection{paragraph}{4}{-2em}%
                               {0pt}%
                               {0pt}%
                               {\normalfont\normalsize\bfseries}}
\makeatother
\begin{document}

For more information, see~\nameref{soft_reset_perf} or~\nameref{something}.

\begingroup
\setlength{\leftskip}{2em}% Correct for \Item adjustment
\Item{perf}:~\label{soft_reset_perf} Indicates that a soft 
  reset has been performed. Here is some more text. Here is some 
  more text. Here is some more text. Here is some more text.
\Item{something}:~\label{something} This is just an interesting 
  item that will be referenced by name at a different location in 
  the document.\par
\endgroup
\end{document}

为了模拟itemize环境,我使用负缩进(无缩进?)排版了\Item2em因此,为了纠正水平偏移,左边距被向右推了2em(通过设置\leftskip)。有关 定义中特定组件的帮助\Item,请考虑阅读在哪里可以找到类似 LaTeX 的 \@startsection 命令的帮助文件或文档?

虽然我已经用过nameref,它同样适用于hyperref

答案2

\documentclass{article}
\usepackage{nameref}
\begin{document}

For more information, see~\nameref{soft_reset_perf} or~\nameref{something}.

\paragraph{perf}:~\label{soft_reset_perf} Indicates that a soft 
  reset has been performed. Here is some more text. Here is some 
  more text. Here is some more text. Here is some more text.
\paragraph{something}:~\label{something} This is just an interesting 
  item that will be referenced by name at a different location in 
  the document.

\end{document}

在此处输入图片描述

相关内容