Cleveref-更改段落的 crefname 以包含段落标题

Cleveref-更改段落的 crefname 以包含段落标题

我想改变\crefname段落,使其产生“段落”而不是编号

常规 latex 命令\nameref已经生成标题,但前面没有“段落”

到目前为止我已经尝试了以下变体:

\documentclass{article}
\usepackage{hyperref}
\usepackage[nameinlink]{cleveref}
\crefname{paragraph}{paragraph \nameref}{paragraphs \nameref}
\Crefname{paragraph}{Paragraph \nameref}{Paragraphs \nameref}

\begin{document}

\section{Section Title}
\paragraph{First paragraph}\label{par:1}

This is a reference to \cref{par:1}. %Should produce This is a reference to paragraph First paragraph.


\end{document}

我相信该\crefname命令不能\nameref在其定义中采用变量......

有什么建议么?

答案1

楼主明显理解错了:

除非secnumdepth计数器未设置为值“4”(或更高),否则\paragraph根本不会编号并且\refstepcounter不会执行,因此\label{par:1}指的是最后一个计数器被参考步进(section在这种特殊情况下!)

\section{...}使用and then也是‘错误’的\paragraph。不应省略\subsectionand命令。\subsubsection

\theparagraph如果省略它们,则也必须更改宏以防止出现难看的1.0.0.1编号样式。

A\paragraph不是通常意义上的段落,即在运行文本中视觉上分离的一些文本——\paragraph旨在用作另一个结构级别单元(如果确实需要的话!)

\documentclass{article}
\usepackage{hyperref}
\usepackage[nameinlink]{cleveref}

\setcounter{secnumdepth}{4}

\crefname{paragraph}{paragraph}{paragraphs}
\Crefname{paragraph}{Paragraph}{Paragraphs}


\begin{document}
This is a reference to \cref{par:1}. %Should produce This is a  reference to paragraph First paragraph.
Another reference to \Cref{par:1}%
\clearpage
\section{Section Title}
\subsection{Subsection title}
\subsubsection{Subsubsection title}
\paragraph{First paragraph}\label{par:1}



\end{document}

在此处输入图片描述

使用“假”\cnameref命令更新:

\documentclass{article}
\usepackage{hyperref}
\usepackage[nameinlink]{cleveref}

\setcounter{secnumdepth}{4}



\crefname{paragraph}{paragraph}{paragraphs}
\Crefname{paragraph}{Paragraph}{Paragraphs}

\makeatletter
\DeclareRobustCommand{\cnameref}[1]{%
  \namecref{#1} \nameref{#1}%
}%
\DeclareRobustCommand{\Cnameref}[1]{%
  \nameCref{#1} \nameref{#1}%
}





\makeatother



\begin{document}

This is a reference to \cnameref{par:1}. %Should produce This is a reference to paragraph First paragraph.

Another reference to \Cnameref{par:1}

\clearpage
\section{Section Title}
\subsection{Subsection title}
\subsubsection{Subsubsection title}
\paragraph{First paragraph}\label{par:1}



\end{document}

相关内容