7

In this example, how can I customize \cref{fig:1,fig:3}? I.e instead of having (Figs. 1 and 3), I would like to have (Figs. 1 et 3). The same question with \Cref{fig:1,fig:3}.

\documentclass[10pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{todonotes}
\usepackage[colorlinks,linkcolor=blue]{hyperref}
\usepackage[nameinlink,capitalise]{cleveref}

\newcommand{\crefrangeconjunction}{--}

\begin{document}

\begin{figure}[t!]
\caption{Missing figure 1.}\label{fig:1}
\caption{Missing figure 2.}\label{fig:2}
\caption{Missing figure 3.}\label{fig:3}
\end{figure}

\obeylines 
Single figure: \cref{fig:2}
Two figures: \cref{fig:1,fig:3}
Range of consecutive figures: \cref{fig:1,fig:2,fig:3}, \crefrange{fig:1}{fig:3}

\vspace{.5cm}

Single figure: \Cref{fig:2}
Two figures: \Cref{fig:1,fig:3}
Range of consecutive figures: \Cref{fig:1,fig:2,fig:3}, \Crefrange{fig:1}{fig:3}

\end{document}
1
  • 2
    Is your document language French, Latin, or something else? (et means and in both French and Latin...)
    – Mico
    Nov 7, 2017 at 23:01

3 Answers 3

4

You need to set the macro \crefpairconjunction. Specifically, run

\newcommand{\crefpairconjunction}{ et }

after loading cleveref.

See also p. 13 of the user guide of the cleveref package.

9
  • in relation to the same subject, how to have: \cref{tab:1} gives: Tab. 1 and \Cref{tab:1} gives: Tableau 1
    – simo
    Nov 8, 2017 at 0:19
  • 1
    I found on page 14 the commands: \crefname{table}{Tab.}{Tabs.} and \Crefname{table}{Tableau}{Tableaux}
    – simo
    Nov 8, 2017 at 0:31
  • 3
    @simo If you adopt my solution these names don't have to be adjusted manually at all.
    – Alan Munn
    Nov 8, 2017 at 1:03
  • I have not adobted your solution Alan Munn (which is simple and practical) because I want to keep the abbreviations Fig. Figs. Tab. and Tabs. Thank you so much for your contribution.
    – simo
    Nov 8, 2017 at 12:20
  • @simo - To keep the names Fig., Figs., Tab., and Tabs. while also specifying the language option french, all you'd need to do is issue the instructions \crefname{figure}{Fig.}{Figs.}, \Crefname{figure}{Fig.}{Figs.}, \crefname{table}{Tab.}{Tabs.}, and \Crefname{table}{Tab.}{Tabs.}`.
    – Mico
    Nov 8, 2017 at 12:48
13

The cleveref package is babel-aware, so it suffices to load babel and add french to the cleveref options. In this example I've turned off the : shorthand defined for French because your labels have : in them.

In fact the use of babel isn't actually needed for this to work, you can simply pass the french option to cleveref and the French conjunction will be used.

When used this way, cleveref will also adjust the names of the relevant elements correctly (Tableau(x) etc.).

\documentclass[10pt,a4paper]{article}
\usepackage[french,shorthands=!;?]{babel}

\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{todonotes}
\usepackage[colorlinks,linkcolor=blue]{hyperref}
\usepackage[nameinlink,capitalise,french]{cleveref}
\newcommand{\crefrangeconjunction}{--}

\begin{document}

\begin{figure}[t!]
\caption{Missing figure 1.}\label{fig:1}
\caption{Missing figure 2.}\label{fig:2}
\caption{Missing figure 3.}\label{fig:3}
\end{figure}

\obeylines 
Single figure: \cref{fig:2}
Two figures: \cref{fig:1,fig:3}
Range of consecutive figures: \cref{fig:1,fig:2,fig:3}, \crefrange{fig:1}{fig:3}

\vspace{.5cm}

Single figure: \Cref{fig:2}
Two figures: \Cref{fig:1,fig:3}
Range of consecutive figures: \Cref{fig:1,fig:2,fig:3}, \Crefrange{fig:1}{fig:3}

\end{document}

output of code

4
  • Your write-up may create the impression that cleveref employs the babel package if the option french is set. That's not the case: cleveref has its own set of language-specific rules, which get executed whether or not babel is loaded.
    – Mico
    Nov 7, 2017 at 22:55
  • 1
    @Mico Thanks. The documentation isn't clear on how they interact. So the solution is even simpler: just add french to the cleveref options.
    – Alan Munn
    Nov 7, 2017 at 22:58
  • 2
    cleveref does interact with babel. I guess @Mico is right to say that if only french is required, if the option is passed to cleveref in the absence of babel it will work as expected. But if two languages are employed in the document, cleveref will adapt to \foreignlanguage (or equivalent) accordingly, then requiring babel.
    – gusbrs
    Nov 7, 2017 at 23:06
  • 1
    @gusbrs - The OP hasn't indicated whether he/she uses babel or polyglossia and which language(s) are used in the document. (French is of course a distinct possibility, but so is Latin...) cleveref cooperates with ("interacts"?) with both babel and polyglossia.
    – Mico
    Nov 8, 2017 at 7:46
-1

Thank you very much for all your contributions, now I can say I got a satisfactory result:

\documentclass[10pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{todonotes}
\usepackage[colorlinks,linkcolor=blue]{hyperref}
\usepackage[nameinlink,capitalise]{cleveref}

\newcommand{\crefrangeconjunction}{--}
\newcommand{\crefpairconjunction}{ et }
\crefname{table}{Tab.}{Tabs.}
\Crefname{table}{Tableau}{Tableaux}

\begin{document}

\begin{figure}[t!]
\caption{Missing figure 1.}\label{fig:1}
\caption{Missing figure 2.}\label{fig:2}
\caption{Missing figure 3.}\label{fig:3}
\end{figure}
%=================   
\begin{table}
   \caption{Exemple d'environnement table 1}  \label{tab1}
   \caption{Exemple d'environnement table 2}  \label{tab2}   
   \caption{Exemple d'environnement table 2}  \label{tab3}
\end{table}
%=================

\obeylines % just for this example
Single figure: \cref{fig:2}
Two figures: \cref{fig:1,fig:3}
Range of consecutive figures: \cref{fig:1,fig:2,fig:3}, \crefrange{fig:1}{fig:3}

\vspace{.5cm}

Single figure: \Cref{fig:2}
Two figures: \Cref{fig:1,fig:3}
Range of consecutive figures: \Cref{fig:1,fig:2,fig:3}, \Crefrange{fig:1}fig:3}

\vspace{.5cm}

Single table: \cref{tab1} ; \Cref{tab1}
Two figures: \cref{tab1,tab2}  ; \Cref{tab1,tab2}
Range of consecutive figures: \cref{tab1,tab2,tab3}, \Crefrange{tab1}{tab3}

\end{document}
2
  • 4
    Since this doesn't add anything to the answers already here, it's not really needed as an answer. See Should I self answer my question? for some discussion.
    – Alan Munn
    Nov 8, 2017 at 1:03
  • @Alan Munn: In my answer I tried to complete the solution of Mico, to have the same thing with the tables.
    – simo
    Nov 8, 2017 at 12:41

You must log in to answer this question.

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