0

I know there are many other questions w.r.t. the topic I m talking about. However, I wasn't able to find the exact solution.

My problem is that I want to simply have 6 subfigures (2 rows of 3) and be able to reference them (e.g. with autoref or whatever) and it should show as something like (e.g. when referencing Figure 1 a): ''Figure 1a" or similar (doesn't matter if it is Fig. or Figure) but it absolutely must mention the figure number AND subfigure. (By the way I do not understand why the default is like "1a" because obviously if you have multiple figures with a subfig (a) you cannot tell which one is referenced ! )

The last (desesperate) try, (and following the Overleaf tutorial! https://www.overleaf.com/learn/latex/How_to_Write_a_Thesis_in_LaTeX_(Part_3):_Figures,_Subfigures_and_Tables#Subfigures ) is :

\begin{figure}
     \centering
     \begin{subfigure}
         \centering
         \includegraphics[width = 1.51in]{img1}
         \caption{}
         \label{fig:label1}
     \end{subfigure}
     \hfill
     \begin{subfigure}
         \centering
         \includegraphics[width = 1.51in]{img2}
         \caption{}
         \label{fig:label2}
     \end{subfigure}
     \hfill
     \begin{subfigure}
         \centering
         \includegraphics[width = 1.51in]{img3}
         \caption{}
         \label{fig:label3}
     \end{subfigure}
          \hfill
     \begin{subfigure}
         \centering
         \includegraphics[width = 1.51in]{img4}
         \caption{}
         \label{fig:label4}
     \end{subfigure}
     \begin{subfigure}
         \centering
         \includegraphics[width = 1.51in]{img5}
         \caption{}
         \label{fig:label5}
     \end{subfigure}
          \hfill
     \begin{subfigure}
         \centering
         \includegraphics[width = 1.51in]{img6}
         \caption{}
         \label{fig:label6}
     \end{subfigure}
        \caption{blah blah blah ... }
        \label{fig:homodynReconstrComp}
\end{figure}

Moreover, if I add a caption like : caption{a} etc. it will display figures in a nonsensical way and reference each subfigure as a new figure! e.g. the one which should be Figure 1b will be called Figure 2b instead of Figure 1b. It seems that the Overleaf doc is wrong.

Also, I tried this simple example which does not work correctly either:

\begin{figure}
\centering     %%% not \center
\subfigure[Figure A]{\label{fig:a}\includegraphics[width=60mm]{example-image-a}}
\subfigure[Figure B]{\label{fig:b}\includegraphics[width=60mm]{example-image-b}}
\caption{my caption}
\end{figure}

of course with the package \usepackage{subfigure}

Any help is greatly appreciated, especially while I still have some hair on my head !*

And the full list of packages that i m using is :

\documentclass{article}
\usepackage[utf8]{inputenc}

\usepackage{graphicx}
\usepackage{subfigure}
\usepackage{hyperref}
\usepackage{url}
%for fig mosaic
\usepackage{rotating}
\usepackage{subfig}
%\usepackage[symbol]{footmisc}
\usepackage{listings}
\usepackage{amsmath}
\usepackage[table,xcdraw]{xcolor}
\usepackage{tabularx} 
\usepackage{cite}
\usepackage{float}
\usepackage{caption}
\usepackage{subcaption}

\usepackage{cleveref}%important

\usepackage{soul}

%\usepackage[style=ieee]{biblatex}
\usepackage[
backend=biber,
style=ieee,
]{biblatex}
\addbibresource{biblio1.bib}

1 Answer 1

2

You're missing a fundamental part: after \begin{subfigure} you need to specify the width reserved for the object.

Instead of the arbitrarily chosen 1.51in I used 0.3\textwidth. Inside subfigure you can refer to this width as \textwidth.

With \cref from cleveref you automatically get fig. in front of the cross-reference.

\documentclass{article}
\usepackage{subcaption}
\usepackage{graphicx}
\usepackage{cleveref}

\begin{document}

References: \cref{fig:label1}, \cref{fig:label2} and \cref{fig:homodynReconstrComp}

\begin{figure}
\centering

\begin{subfigure}{0.3\textwidth}
  \includegraphics[width = \textwidth]{example-image}
  \caption{}
  \label{fig:label1}
\end{subfigure}\hfill
\begin{subfigure}{0.3\textwidth}
  \includegraphics[width = \textwidth]{example-image}
  \caption{}
  \label{fig:label2}
\end{subfigure}\hfill
\begin{subfigure}{0.3\textwidth}
  \includegraphics[width = \textwidth]{example-image}
  \caption{}
  \label{fig:label3}
\end{subfigure}

\bigskip

\begin{subfigure}{0.3\textwidth}
  \includegraphics[width = \textwidth]{example-image}
  \caption{}
  \label{fig:label4}
\end{subfigure}\hfill
\begin{subfigure}{0.3\textwidth}
  \includegraphics[width = \textwidth]{example-image}
  \caption{}
  \label{fig:label5}
\end{subfigure}\hfill
\begin{subfigure}{0.3\textwidth}
  \includegraphics[width = \textwidth]{example-image}
  \caption{}
  \label{fig:label6}
\end{subfigure}

\caption{blah blah blah ... }
\label{fig:homodynReconstrComp}

\end{figure}

\end{document}

enter image description here

3
  • thanks for you quick answer! It looks great, still I must be doing something wrong because I get an error message if i dont use \usepackage{subfigure} it tells me "undef. env. subfigure" and if I use \usepackage{subfigure} then I get:
    – SheppLogan
    Commented Jun 10, 2020 at 9:14
  • "missing number treated as 0, illegal unit of measurement", any ideas? (I will also add to my OP the exact list of packages that i m using)
    – SheppLogan
    Commented Jun 10, 2020 at 9:15
  • oh I just noticed I had an extract subfig package usage ! Now it's working! thank you for your great answer. This is what should be in the Overleaf documentation instead of the nonsense they have.
    – SheppLogan
    Commented Jun 10, 2020 at 9:21

You must log in to answer this question.

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