3

I have a little problem and would be extremely grateful if somebody could help me.

Indeed, I am having trouble while referencing images. In fact here is my code:

main.tex:

\documentclass[french, 12pt, twoside, openany]{book}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{subfigure}
\usepackage{amsmath}
\usepackage{fancyhdr}
\usepackage{float}
\usepackage[acronym,nonumberlist]{glossaries}
\usepackage{pdflscape}
\usepackage{adjustbox}
\usepackage{geometry}

\usepackage[hidelinks,linktoc=all]{hyperref} % Modification ici

\geometry{
  a4paper,
  left=20mm,
  right=20mm,
  top=20mm,
  bottom=20mm
}

\begin{document}
\begin{figure}
    \caption{Example}
        \centering
        \subfloat[ Something 1]{\label{sub:1}\includegraphics[width=0.47\textwidth]{example-image}}\qquad
        \subfloat[ Something 2]{\label{sub:2}\includegraphics[width=0.47\textwidth]{example-image}}
        
        \label{fig:test}
    \end{figure}
    
\cref{sub:1}
\end{document}

Here is the output : current output

I would like to change two things :

  1. I wish to have labels (a) and (b) under the two pictures, aligned with them but the label "figure : Example" must stay on top of both pictures.
  2. I would really like to have the "figure" written in this style : desired font

I would really appreciate any kind of help and thank everybody in advance.

2 Answers 2

4

The subfigure package has been obsolete for several years. You can use either subfig or subcaption and the latter is usually recommended, unless the class doesn't support it, which is not the case of book.

You also need babel for French and cleveref for \cref.

However \cref has an annoying issue when babel-french is used: labels with a colon aren't supported and cause low level errors. I suggest using a hyphen, or \string: in the argument of \cref as shown below.

The caption label “Figure” will automatically be in small caps with bebel-french. You just need to instruct that the caption should be at the top and at the bottom in subfigures.

\documentclass[french, 12pt, twoside, openany]{book}
%\usepackage[utf8]{inputenc}% no longer needed
\usepackage[T1]{fontenc}
\usepackage{babel}
\usepackage{graphicx}
\usepackage{subcaption}% subfigure is obsolete
\usepackage{amsmath}
\usepackage{fancyhdr}
%\usepackage{float}% what for?
\usepackage[acronym,nonumberlist]{glossaries}
\usepackage{pdflscape}
\usepackage{adjustbox}
\usepackage{geometry}

\usepackage[hidelinks,linktoc=all]{hyperref} % Modification ici
\usepackage{cleveref}% for \cref

\geometry{
  a4paper,
  left=20mm,
  right=20mm,
  top=20mm,
  bottom=20mm,
  heightrounded, % <-- important for book
}

\captionsetup[figure]{
  position=top,
}
\captionsetup[subfigure]{
  position=bottom,
}

\begin{document}

\begin{figure}
\centering

\caption{Example}
\label{fig:test}

\begin{subfigure}{0.47\textwidth}
\includegraphics[width=\textwidth]{example-image}

\caption{Something 1\label{sub:1}}
\end{subfigure}\hfill
\begin{subfigure}{0.47\textwidth}
\includegraphics[width=\textwidth]{example-image}

\caption{Something 2\label{sub:2}}
\end{subfigure}
        
\end{figure}
    
\cref{sub\string:1}

\end{document}

I guess you'll agree that using hyphens instead of colons is better.

output

If you want a colon (French style) instead of the dash, replace

\captionsetup[figure]{
  position=top,
}

with

\DeclareCaptionLabelSeparator{frenchcolon}{\FBcolonspace:\FBcolonspace}
\captionsetup[figure]{
  position=top,
  labelsep=frenchcolon,
}

enter image description here

3

Use the package subcaption and its options, omit subfig. You need the following lines in the preamble.

\usepackage{subcaption}
\captionsetup{labelfont=sc}
\subcaptionsetup{labelfont=rm,position=bottom}

This will affect all floats. If you want to have this particular formatting only for figures, add the optional argument [figure].

\captionsetup[figure]{labelfont=sc}
\subcaptionsetup[figure]{labelfont=rm,position=bottom}

For details see the documentation of the subcaption package

enter image description here

\documentclass{book}
\usepackage{graphicx}
\usepackage{subcaption}
\captionsetup{labelfont=sc}
\subcaptionsetup{labelfont=rm,position=bottom}
\usepackage{cleveref}

\begin{document}
\begin{figure}
    \centering
    \caption{Example}
    \label{fig:test}
    \subcaptionbox
      {Something 1\label{sub:1}}
      {\includegraphics[width=0.47\textwidth]{example-image}}\qquad
    \subcaptionbox
      {Something 2\label{sub:2}}
      {\includegraphics[width=0.47\textwidth]{example-image}}
\end{figure}
    
\cref{sub:1}
\end{document}
2
  • Thank you for your answer but it unfortunately doesn't work. Here is the error : Package caption Error: The counter `subfigure' was defined by
    – Gigi
    Commented Jul 8 at 21:54
  • 1
    @Gigi Probably you still have the line \usepackage{subfigure} in your preamble. Remove it. Otherwise, take my code from above, which works, and add little by little parts from your code until the error appears.
    – gernot
    Commented Jul 9 at 6:54

You must log in to answer this question.

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