2

I have recently found "cref". Very practical for equations, figures, and tables. But for referring to multiple sections it does not work.

A concrete example:

(Sorry for the long lables by the way)

Chapters \mref{par: Theoretical Background OPF SOPF SOPF in load space,par: Theoretical Background OPF SOPF SOPF in load space in practice}

gives:

Chapters 2.7.5.2, 2.7.5.3

as output, whereas

Chapters \cref{par: Theoretical Background OPF SOPF SOPF in load space,par: Theoretical Background OPF SOPF SOPF in load space in practice}

gives:

Chapters ?? 2.7.5.2?? 2.7.5.3

as output.

Why is it like this? What can I do about it?

Update:

I paste a small .tex example file in the below:

\documentclass[a4paper]{article}

\usepackage[ireport]{KTHEEtitlepage}

% Packages used in the main document for this particular example:
\usepackage{url}
\usepackage{amstext}

\usepackage[english]{babel} % swedish
\usepackage[T1]{fontenc}
\usepackage[latin1]{inputenc}

\usepackage{hyperref}

\usepackage{amsmath}
\usepackage{amsfonts} % mathbb

\usepackage{xparse}

\usepackage{dsfont}

\usepackage{graphicx}

\usepackage{tikz}
\usepackage{pgf}
\usepackage{pgfplots}
\usetikzlibrary{plotmarks}
\usepackage{pgfmath}

\usepackage[nocompress]{cite}

\usepackage{hyperref}
\usepackage[capitalize]{cleveref}

\newcommand{\sgn}{\operatorname{sgn}}


\ExplSyntaxOn
\NewDocumentCommand{\mref}{m}{\quinn_mref:n {#1}}
\seq_new:N \l_quinn_mref_seq
\cs_new:Npn \quinn_mref:n #1
 {
  \seq_set_split:Nnn \l_quinn_mref_seq { , } { #1 }
  \seq_pop_right:NN \l_quinn_mref_seq \l_tmpa_tl
%  ( % print the left parenthesis
  \seq_map_inline:Nn \l_quinn_mref_seq
    { \ref{##1},\nobreakspace } % print the first references
  \exp_args:NV \ref \l_tmpa_tl % print the last or only one
%  ) % print the right parenthesis
 }
\ExplSyntaxOff

\begin{document}

\ititle{This is a report, Revision date 2016-10-21}
\isubtitle{This is the subtitle}
\iauthor{Lars Abrahamsson}
\idate{2016}
\irefnr{Report number 345474574567457}



\iaddress{At research group \\
  At department \\
  At University }


\makeititle

\setcounter{tocdepth}{5}
\setcounter{secnumdepth}{5}

% Everything below is exactly as for a normal document and
% the layout of that document should not be affected in any
% way by the title page.

\title{The title}

\author{The Author}


\tableofcontents

\listoftables

\listoffigures

\maketitle


\section{Test 1}

\label{sec: Test 1}

sdgdffg

\section{Test 2}

\label{sec: Test 2}

xfbgdfhhfd

Please, refer to \cref{sec: Test 1,sec: Test 3}

\section{Test 3}

\label{sec: Test 3}

Please, refer to Chapters \mref{sec: Test 1,sec: Test 2}. 


\paragraph{Paragraph with short label}

\label{par: Short Name}

fff

Just cref: \cref{par: Short Name}

\subsubsection{Balle}

\label{subsubs: balle}

Just cref: \cref{subsubs: balle}


\end{document} 

The output on page 2 (the relevant one) then becomes like the picture below:

enter image description here

3
  • 1
    Welcome! Please provide a complete minimal document i.e. code we can compile to reproduce the problem. Using \cref for multiple references has worked fine for me. What is \mref?
    – cfr
    Commented Nov 5, 2016 at 1:51
  • Is \mref an alias for \labelcref?
    – Mico
    Commented Nov 5, 2016 at 3:54
  • Hi \mref is a command I created earlier since I did not have \cref. I identified the problem to be related to refering to paragraphs. It works for subsubsections, but it seems not to work below that level. Commented Nov 8, 2016 at 12:19

2 Answers 2

2

Completing you code to create a minimal example, the only issue is that I need to remove Chapters and use \Cref to get the capitalisation right.

\documentclass{book}
\usepackage{cleveref}
\begin{document}
\chapter{a}\label{par: Theoretical Background OPF SOPF SOPF in load space}
\chapter{b}\label{par: Theoretical Background OPF SOPF SOPF in load space in practice}
\Cref{par: Theoretical Background OPF SOPF SOPF in load space,par: Theoretical Background OPF SOPF SOPF in load space in practice}
\end{document}

multiple references

It is, however, rather confusing to use par: in labels for chapters. I would suggest using chap: or ch: or whatever instead. (Unless par is an abbreviation for the word for chapter in your language of preference, of course.)

4
  • Well. It is not a chapter, but I am ordered to use the term "Chapter" instead of "Section" or "Paragraph". It is not the most important issue here, but I agree in principle. "Par" is an abbreviation for "paragraph". The problem in your code example is that you refer to "(Main) Chapters", I want to be able to refer to sections, subsections, subsubsections, paragraphs, and subparagraphs as well. Thank you this far. Commented Nov 8, 2016 at 12:23
  • It will work just the same if they are sections or paragraphs or whatever. This is why you should provide a proper minimal example - obviously, people are going to guess that a chapter is created with \chapter. But, as it happens, it will work just the same if it is \section or \subsection or whatever.
    – cfr
    Commented Nov 8, 2016 at 15:25
  • Sorry. There is not speace enough in this "SMS-like" box to paste that. Commented Nov 9, 2016 at 13:40
  • So I edited the main question above. Commented Nov 9, 2016 at 13:53
1

You need to provide the instructions

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

to inform cleveref which label it should use when typesetting cross-references to objects associated with the paragraph counter.

If you'll be using numbered subparagraph-level headers in your document, and if you need to cross-reference them with \cref, you need to provide the following instructions as well:

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

I wouldn't use "subparagraph(s)" as the label -- it looks clunky to me.

1
  • If you need to use the label "chapter" for all sectioning headings, be they of type chapter, section, subsection, etc., you should probably write \crefname{paragraph}{chapter}{chapters}, \crefname{subparagraph}{chapter}{chapters}, etc.
    – Mico
    Commented Nov 9, 2016 at 17:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .