3

I'm writing a large document where I'm using pretty much every level of sectioning from Part right down to paragraph.

I've been using varioref in conjunction with hyperref and cleverref to 'intelligently' handle all my referencing (I probably shouldn't be using all three, but it's given me the desired effect so far.

The only problem is, the referencing doesn't seem to work with paragraphs as I would expect. The references resolve to automatically insert the word "Section" when referencing a (sub(sub))section, "Figure" when referencing a figure and so on, but they don't insert the word "Paragraph" or "Section" when referencing a paragraph.

e.g: Numbering of sections with varioref

I had thought the problem would be because I have defined a custom paragraph format, but you should be able to see from the MWE below that it happens with the 'normal' paragraph too.

Is there something I'm missing to make these packages respect paragraphs like they do for everything else?

\documentclass[a4paper, oneside, 11pt]{report}
\usepackage[left=4cm, right=2cm, top=1.5cm, bottom=2.5cm]{geometry}
\usepackage{lipsum}
\usepackage{varioref}
\usepackage[hidelinks]{hyperref} 
\usepackage[capitalise,noabbrev]{cleveref}
\usepackage{tocloft}
\setcounter{secnumdepth}{5} % Number deeper sections
\setcounter{tocdepth}{5}% Number deeper sections

\newcommand{\myparagraph}[1]{\paragraph{#1}\mbox{}\vspace{0.3cm}\\} % adds a new paragraph environment called by \myparagraph


\begin{document}

\tableofcontents

\chapter{My First Chapter}\label{chapterone}
\section{My First Section}\label{sectionone}
\subsection{My First Subsection}\label{subsectionone}
\subsubsection{My First Subsubsection}\label{subsubsectionone}
\paragraph{My First Standard Paragraph}\label{mystandardparagraph}
\lipsum[1]
\myparagraph{My First Custom Paragraph}\label{mycustomparagraph}
\lipsum[2]

\chapter{My Second Chapter}
\section{My Second Section}
I can reference \vref{chapterone} and \vref{sectionone} and \vref{subsectionone} and \vref{subsubsectionone}

\subsection{My Second Subsection}
But not \vref{mystandardparagraph} and \vref{mycustomparagraph}...

\end{document}
Bernard
  • 271,350

1 Answers1

6

cleveref simply doesn't know how to correctly reference paragraph numbers and in fact issues a warning in the LOG file. To tell the package how to “call” these types of references use

\crefname{labeltype}{singular}{plural}

In your example it would be

\documentclass[a4paper, oneside, 11pt]{report}
\usepackage[left=4cm, right=2cm, top=1.5cm, bottom=2.5cm]{geometry}
\usepackage{lipsum}
\usepackage{varioref}
\usepackage[hidelinks]{hyperref} 
\usepackage[capitalise,noabbrev]{cleveref}
\usepackage{tocloft}
\setcounter{secnumdepth}{5} % Number deeper sections
\setcounter{tocdepth}{5}% Number deeper sections

\newcommand{\myparagraph}[1]{\paragraph{#1}\mbox{}\vspace{0.3cm}\\} % adds a new paragraph environment called by \myparagraph

\crefname{paragraph}{paragraph}{paragraphs}% <<<---- added

\begin{document}

\tableofcontents

\chapter{My First Chapter}\label{chapterone}
\section{My First Section}\label{sectionone}
\subsection{My First Subsection}\label{subsectionone}
\subsubsection{My First Subsubsection}\label{subsubsectionone}
\paragraph{My First Standard Paragraph}\label{mystandardparagraph}
\lipsum[1]
\myparagraph{My First Custom Paragraph}\label{mycustomparagraph}
\lipsum[2]

\chapter{My Second Chapter}
\section{My Second Section}
I can reference \vref{chapterone} and \vref{sectionone} and \vref{subsectionone} and \vref{subsubsectionone}

\subsection{My Second Subsection}
But not \vref{mystandardparagraph} and \vref{mycustomparagraph}...

\end{document}

Note that a manually set \crefname is not touched by the capitalise option by design. The manual (p. 10) says:

All the default cross-reference formats will then have the first letter capitalised, as will the automatically generated \cref variants (see Sections 8.1.2 and 8.2). (However, if you explicitly define a \cref variant to not be capitalised, cleveref will still honour your definition. In other words, you’re responsible for defining the capitalisation correctly in your own format definitions.)

Thus you can use \crefname to overwrite the auto capitalisation of some reference types.

Tobi
  • 56,353
  • Out of interest, is there a way to make cleveref respect the capitalisation of "Paragraph", as it does with the [capitalise] option on Sections etc. I can hard-code it as a quick work around, but that doesn't seem to be whatever the TeX version of 'pythonic' is :P – Joe Healey Jul 09 '18 at 14:34
  • No. The option only works for the default ones. See manual of the package, § 7.1, p. 10. – Tobi Jul 10 '18 at 12:08