
Estou tentando colocar uma figura que já possui sublegendas. Escrevi:
\documentclass{article}
\usepackage{subcaption}
\usepackage{hyperref}
\usepackage{graphicx}
\usepackage{blindtext}
\begin{document}
A reference to \autoref{fig1c}
\begin{figure}[htb]
\centering
\includegraphics[width=0.5\textwidth]{example-image}
\caption{Image description:
\textbf{(a)}~number 1,
\textbf{(b)}~number 2,
\textbf{(c)}~number 3 and
\textbf{(d)}~number 4
\label{fig1}}
\phantomsubcaption\label{fig1a}
\phantomsubcaption\label{fig1b}
\phantomsubcaption\label{fig1c}
\phantomsubcaption\label{fig1d}
\end{figure}
a reference to \autoref{fig1d}
\end{document}
Mas quando cruzo os números, o número deles está incorreto.
Como posso consertar isso?
Responder1
Você precisa fazer duas alterações:
Coloque as instruções
\phantomsubcaption
associadas\label
antesa diretiva principal\caption
e suas\label
instruções associadas.As
\phantomsubcaption
diretivasdeveser colocados em um grupo TeX sozinhos. (Consulte a página 10 do guia do usuário dosubcaption
pacote.)
Um MWE completo:
\documentclass{article}
\usepackage{subcaption}
\usepackage{graphicx}
\usepackage{blindtext}
\usepackage[colorlinks]{hyperref} % <-- load this package **last**
\begin{document}
A cross-reference to \autoref{fig1c}.
\begin{figure}[htb]
\centering
\includegraphics[width=0.5\textwidth]{example-image}
\begingroup % encase the \phantomsubcaption directives in a TeX group
\phantomsubcaption\label{fig1a}
\phantomsubcaption\label{fig1b}
\phantomsubcaption\label{fig1c}
\phantomsubcaption\label{fig1d}
\endgroup
\caption{%
\textbf{(a)}~number 1,
\textbf{(b)}~number 2,
\textbf{(c)}~number 3, and
\textbf{(d)}~number 4}
\label{fig1}
\end{figure}
A cross-reference to \autoref{fig1d}.
\end{document}