0

I ploted a big figure with several subfigures in it using matplotlib, because the library provides many features that are difficult to implement in tex (like shared label and shared axis). However, I would like to \ref these subfigures just like subcaption in tex. Is there any methods can do the trick?

My requirement is nearly the same as the question in Several labels for big figure with included subplots.

However, the solution does not work when hyperref is imported. Since the answer is posted 3 years ago and it seems that it would not get any updates, I asked the question again.

1 Answer 1

0

I figured out a work around:

\documentclass{article}
\usepackage{graphicx}
\usepackage{hyperref}

\makeatletter
\newcommand{\phantomlabel}[2]{
    \protected@write\@auxout{}{
        \string\newlabel{#2}{
            {\@currentlabel#1}{\thepage}
            {\@currentlabel#1}{#2}{}
        }
    }
    \hypertarget{#2}{}
}
\makeatother

\begin{document}
Figure~\ref{fig:a} consists of sub-figure~\ref{fig:a:left_plot},
sub-figure~\ref{fig:a:right_plot}, and
sub-figure~\ref{fig:a:somewhere else}.
\begin{figure}
  \includegraphics[width=\textwidth]{example-image-a}
  \caption{This plot has three parts.}\label{fig:a}
  \phantomlabel{a}{fig:a:left_plot}
  \phantomlabel{b}{fig:a:right_plot}
  \phantomlabel{c}{fig:a:somewhere else}
\end{figure}

Figure~\ref{fig:b} consists of sub-figure~\ref{fig:b:left_plot},
sub-figure~\ref{fig:b:right_plot}, and
sub-figure~\ref{fig:b:somewhere else}.
\begin{figure}
  \includegraphics[width=\textwidth]{example-image-b}
  \caption{This plot has three parts.}\label{fig:b}
  \phantomlabel{a}{fig:b:left_plot}
  \phantomlabel{b}{fig:b:right_plot}
  \phantomlabel{c}{fig:b:somewhere else}
\end{figure}
\end{document}

The code is modified from the answer posted by @gernot in the question I linked. The basic idea is to create a hyper-target in the corresponding phantom label position without writing text.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .