
すでにサブキャプションが付いている図を配置しようとしています。次のように書きました:
\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}