7

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}
2
  • Can you explain why the label has to be within the caption environment here? Oct 15, 2018 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. Oct 15, 2018 at 14:11

1 Answer 1

8

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}
12
  • 1
    @sandu or I could edit my answer...
    – FionaSmith
    May 27, 2014 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, 2014 at 9:58
  • 1
    @TorbjørnT. your comment now incorporated into the answer. Thanks.
    – FionaSmith
    May 27, 2014 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. May 27, 2014 at 10:04
  • 2
    No, it compiled fine, and there may not be any clashes between the two (I don't know), it just seemed superfluous to add subfig. May 27, 2014 at 10:21

You must log in to answer this question.

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