
我正在嘗試放置一個已經有字幕的圖形。我寫:
\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 組中。 (請參閱包裝盒使用者指南第 10 頁subcaption
。)
完整的 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}