2

I'd like to change the \crefname for paragraphs so that it produces "paragraph " instead of the numbering

The regular latex command \nameref already produces the title but without "paragraph" in front

So far I've tried variations of the below:

\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}

I believe the \crefname command can't take the \nameref variable in it's definition...

Any suggestions?

3
  • Welcome to TeX.SX! Your crefname for paragraph never comes into action, since there's no label for paragraph here. \label{par:1} refers to the section, not the paragraph, since First paragraph is not numbered, so the label is not what you expect
    – user31729
    Jul 23 '16 at 9:34
  • You're right, \nameref should not appear in the \crefname setup
    – user31729
    Jul 23 '16 at 9:41
  • Wouldn't it be better to reference the short paragraph name, e.g., \paragraph[Short name]{First paragraph}? Jun 18 at 14:40
2

There's a misunderstanding by the O.P. apparently:

Unless the secnumdepth counter is not set to the value of '4' (or higher) the \paragraph will not be numbered at all and \refstepcounter is not executed, so \label{par:1} refers to the last counter being ref-stepped (which is section in this particular case!)

It's also 'wrong' to use \section{...} and then \paragraph. The \subsection and \subsubsection commands shouldn't be omitted.

If they are omitted, the macro \theparagraph must be changed too to prevent ugly 1.0.0.1 numbering style.

A \paragraph is not a paragraph in the usual sense, i.e. some text visually separated in the running text -- \paragraph is meant to be used as another structure level unit (if really needed at all!)

\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}

enter image description here

Update with a 'fake' \cnameref command:

\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}
4
  • Thank you for your quick response! This helps a lot already. However, the 'end-goal' is to print 'First paragraph' instead of '1.1.1.1'. That is why I thought somehow the paragraph's title needs to be included in the definition of \crefname{paragraph}
    – Aad
    Jul 23 '16 at 9:52
  • @Aad: Why don't you use \nameref then -- it will print the title of the paragraph etc.
    – user31729
    Jul 23 '16 at 10:01
  • because that only prints the title and not paragraph in front of its title. The point is that I want to avoid too long numbering for paragraph cross-references in my text. So the regular use of 'section 1.2' is fine, but I prefer 'paragraph <par title>' instead of paragraph 1.3.2.4.5
    – Aad
    Jul 23 '16 at 10:04
  • @Aad: Must paragraph appear in the hyperlink as well or is the par title sufficient in the hyperlink? See the update please
    – user31729
    Jul 23 '16 at 10:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.