6

I need to get Figure 1.1 (a) when i put \Cref{fig:NiceImage1}.

I have to use \Cref{fig:NiceImage}\subref{fig:NiceImage1} for getting same result.

\documentclass{scrbook}
\usepackage[demo]{graphicx}
\usepackage{subcaption}

\captionsetup{subrefformat=parens}

\usepackage{cleveref}

\setcounter{chapter}{1}

\begin{document}

  \begin{figure}
    \centering
      \begin{subfigure}{0.31\textwidth}
        \includegraphics[width=\textwidth]{image1}
          \caption{Nice image1}
          \label{fig:NiceImage1}
      \end{subfigure}
      \begin{subfigure}{0.31\textwidth}
        \includegraphics[width=\textwidth]{image1}
          \caption{Nice image 2}
          \label{fig:NiceImage2}
      \end{subfigure}
      \begin{subfigure}{0.31\textwidth}
        \includegraphics[width=\textwidth]{image1}
          \caption{Nice image 3}
          \label{fig:NiceImage3}
      \end{subfigure}
\caption{
\label{fig:NiceImage}
Three images}
\end{figure}

Figure \ref{fig:NiceImage}

Figure \ref{fig:NiceImage} \subref{fig:NiceImage1}

\Cref{fig:NiceImage}

\Cref{fig:NiceImage1}

\end{document}
  • Can you explain why the label has to be within the caption environment here? – Lars Abrahamsson Oct 15 '18 at 14:06
  • Moreover, when I use the wpconf class, it seems to be necessary also in the subfigures to put the labels within the captions. You seem only to have to put the label of the caption of the "common" caption of the figure. – Lars Abrahamsson Oct 15 '18 at 14:11
6

Add the following lines to your preamble and \Cref{fig:NiceImage1} will display "Figure 1.1(a)"

\captionsetup[subfigure]{subrefformat=simple,labelformat=simple}
    \renewcommand\thesubfigure{(\alph{subfigure})}

The complete code is below:

\documentclass{scrbook}
\usepackage[demo]{graphicx}
\usepackage{subcaption}

%\captionsetup{subrefformat=parens}
%\subref{fig:NiceImage1} will not work properly...


\usepackage{cleveref}


\captionsetup[subfigure]{subrefformat=simple,labelformat=simple}
    \renewcommand\thesubfigure{(\alph{subfigure})}


\setcounter{chapter}{1}

\begin{document}

  \begin{figure}
    \centering
      \begin{subfigure}{0.31\textwidth}
        \includegraphics[width=\textwidth]{image1}
          \caption{Nice image1}
          \label{fig:NiceImage1}
      \end{subfigure}
      \begin{subfigure}{0.31\textwidth}
        \includegraphics[width=\textwidth]{image1}
          \caption{Nice image 2}
          \label{fig:NiceImage2}
      \end{subfigure}
      \begin{subfigure}{0.31\textwidth}
        \includegraphics[width=\textwidth]{image1}
          \caption{Nice image 3}
          \label{fig:NiceImage3}
      \end{subfigure}
\caption{
\label{fig:NiceImage}
Three images}
\end{figure}

Figure \ref{fig:NiceImage}

Figure \ref{fig:NiceImage} \subref{fig:NiceImage1}

\Cref{fig:NiceImage}

\Cref{fig:NiceImage1}

\end{document}
  • 1
    @sandu or I could edit my answer... – FionaSmith May 27 '14 at 9:34
  • 1
    @sandu have now edited my answer to further elucidate which are the important bits based on Torbjorn's comment – FionaSmith May 27 '14 at 9:58
  • 1
    @TorbjørnT. your comment now incorporated into the answer. Thanks. – FionaSmith May 27 '14 at 9:58
  • 2
    Sorry for being a nag, but subcaption and subfig have the same purpose, so I don't see why you would use both in the same document. subcaption also provides \subref, for example. – Torbjørn T. May 27 '14 at 10:04
  • 1
    @TorbjørnT. OK I will edit again. My document is only based around what I have done. I had subfig first, I can no longer remember why I added subcaption. I just did a web search to find out whether everything was covered but I didn't find many references to the use of subref. – FionaSmith May 27 '14 at 10:11

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.