I'm trying to reference to subfigures in the main caption of my figure. Unfortunately I'm only getting blanks, not even undefined referencing ??
. What's going on?
\documentclass{report}
\usepackage[superscript]{cite}
\usepackage{mathtools}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}
\begin{document}
Some text.
\begin{figure}[!h]
\centering
\begin{subfigure}[b]{0.4\textwidth}
\centering
\includegraphics[width=\textwidth]{figure1}
\label{fig:fig1}
\end{subfigure}
\begin{subfigure}[b]{0.4\textwidth}
\centering
\includegraphics[width=\textwidth]{figure2}
\label{fig:fig2}
\end{subfigure}
\caption{\protect\subref{fig:fig1} shows figure 1 and \protect\subref{fig:fig2} shows figure 2.}
\end{figure}
\end{document}
subfigure
s actually have a caption. Use\caption{\label{fig:fig1}}
and\caption{\label{fig:fig2}}
in bothsubfigure
s.subfigures
away on purpose. I thought that captions weren't necessary to label subfigures?subcaption
documentation for an example very similar to yours.(a)
, it is not nice to link toa
. The lector wouln't know, what you mean. In this case you should write:The above shows figure 1 (left) and figure 2 (right)
\caption{(a)~shows Figure~1 and~(b) shows Figure~2}
. Because if you wish to switch thesubfigures
, you'd have to change the "hard-coded" image captions as well. As you now know, LaTeX can handle this without the "hard-coding".