子標題包創建了對子圖的不正確交叉引用

子標題包創建了對子圖的不正確交叉引用

我正在嘗試放置一個已經有字幕的圖形。我寫:

\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}

相關內容