我想改变\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
。不应省略\subsection
and命令。\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}