3

A small question concerning the customization of cleveref.

I'm trying to set the format of \cref to get "(Fig. 1)".

I managed to get what I want with

\crefformat{figure}{(#2fig.~#1#3)}

Nevertheless, I sometimes need to add a note to this reference and I would like to get a reference of the type: "(Fig. 1, n ° 1)".

Is it possible to add a postnote in the same way as in biblatex \cite[posnote]{bib}?

I could not find what I wanted in the official documentation or on the website.

Thank you!

\documentclass[french]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage[a4paper]{geometry}
\usepackage{babel}
\usepackage{cleveref}
\usepackage{capt-of}
\usepackage{lipsum}
\providecommand{\numero}{n\textsuperscript{o}\nobreakspace}

\crefformat{figure}{(#2fig.~#1#3)}

\begin{document}  
    \captionof{figure}{Je suis une legende}\label{legende} 
I would like this: (fig.~1, \numero 1)

Not this \cref{legende}, \numero 1

\end{document}
6

As a workaround, you could create a special command with the desired behaviour:

\documentclass[french]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}

\usepackage{capt-of}
\usepackage{cleveref}

\providecommand{\numero}{n\textsuperscript{o}\nobreakspace}

\crefformat{figure}{#2fig.~#1#3}

\usepackage{etoolbox}   
\newcommand{\crefp}[2][]{%
    (\cref{#2}%
    \ifstrempty{#1}{}{%
            , #1%
        }%
    )%
}

\begin{document}  
    \captionof{figure}{Je suis une legende}\label{legende} 

I would like this: (fig.~1, \numero 1)

Not this \crefp[\numero 1]{legende}

\crefp{legende}


\end{document}

enter image description here


This approach also works for a list of labels:

\documentclass[french]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}

\usepackage{capt-of}
\usepackage{cleveref}

\providecommand{\numero}{n\textsuperscript{o}\nobreakspace}

\crefformat{figure}{#2fig.~#1#3}

\usepackage{etoolbox}   
\newcommand{\crefp}[2][]{%
    (\cref{#2}%
    \ifstrempty{#1}{}{%
            , #1%
        }%
    )%
}

\begin{document}  
    \captionof{figure}{Je suis une legende}\label{legende} 
    \captionof{figure}{Je suis une legende}\label{legendee} 

\crefp[\numero 1]{legende,legendee}

\crefp{legende,legendee}

\cref{legende,legendee}

\end{document}

enter image description here

  • Little new problem. In the case where I refer to several labels, the reference no longer works. \crefp{lab1,,lab2} I obtain the first but "??" for the second :(. Any idea ? – Axelito Feb 19 '18 at 11:02
  • @Axelito Works fine for me. Please consider asking a new questions which includes a MWE that demonstrates your problem. – samcarter_is_at_topanswers.xyz Feb 19 '18 at 11:50
  • Oops, I said nothing, I put a space in my document between the comma and the label ... I'm a little foolish – Axelito Feb 19 '18 at 13:40

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.