サブキャプション パッケージはサブ図への誤った相互参照を作成します

サブキャプション パッケージはサブ図への誤った相互参照を作成します

すでにサブキャプションが付いている図を配置しようとしています。次のように書きました:

\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

次の 2 つの変更を行う必要があります。

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

関連情報