我正在尝试放置一个已经有子标题的图形。我写道:
\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}
但当我交叉引用这些数字时,发现它们的数字不正确。
我该如何修复它?
答案1
您需要进行两项更改:
放置
\phantomsubcaption
和相关\label
说明前主要\caption
指令及其相关\label
指令。指令
\phantomsubcaption
必须单独放置在 TeX 组中。(请参阅该subcaption
包的用户指南第 10 页。)
完整的 MWE:
\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}