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}
Mico
  • 506,678
simo
  • 303
  • 2
    Is your document language French, Latin, or something else? (et means and in both French and Latin...) – Mico Nov 07 '17 at 23:01

3 Answers3

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

Alan Munn
  • 218,180
  • 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 07 '17 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 07 '17 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 07 '17 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 08 '17 at 07:46
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.

Mico
  • 506,678
  • in relation to the same subject, how to have:

    \cref{tab:1} gives: Tab. 1 and
    \Cref{tab:1} gives: Tableau 1

    – simo Nov 08 '17 at 00:19
  • 1
    I found on page 14 the commands: \crefname{table}{Tab.}{Tabs.} and \Crefname{table}{Tableau}{Tableaux} – simo Nov 08 '17 at 00:31
  • 3
    @simo If you adopt my solution these names don't have to be adjusted manually at all. – Alan Munn Nov 08 '17 at 01: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 08 '17 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 08 '17 at 12:48
  • @Mico, exactly, your solution is relevant. Thank you – simo Nov 08 '17 at 12:52
  • @Mico- two small problems when I apply the different solutions on my thesis document 1) latex does not accept two points (:) in labels 2) when I use the french option in the usepackage{cleveref}, the compilation takes a lot of time. These problems do not appear in this example. – simo Nov 08 '17 at 13:21
  • @simo - Did you try Alan Munn's solution, viz. \usepackage[french,shorthands=!;?]{babel}? Of course, this makes : non-special, which may not be acceptable. If that's the case, the only solution is not to use : anywhere in the arguments of \label and \cref. – Mico Nov 08 '17 at 13:47
  • @Mico: even with Alan's solution, the problem persists. Fortunately, I usually use - in the labels instead of :. I used : only 7 times. – simo Nov 08 '17 at 19:44
-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}
simo
  • 303