2

I made a figure with matplotlib that has three subfigures in the same .pdf file, similar to this one: Matplotlib gallery example. I included the labels "a)", "b)", "c)" in the image.

To reference the whole image as well as the three image parts individually, I would like to have four labels. This is the behaviour that I already have for different figures that I compose with the subcaption-package (\subfigure command).

However, the only thing that I can create so far is a single label for the whole figure.

\begin{figure}
\includegraphics[width=\textwidth]{plot_with_subplots.pdf}
\caption{This plot has three parts.}
\label{fig:plot}
\end{figure}

Calling "figure \ref{fig:plot}" will result in things like "figure 1". However, I want an additional label like "figure \ref{fig:plot:left_plot}" that translates to "figure 1a".

Thanks.

2

The clean solution is to split the multi-plot into single plots and include them separately as sub-figures (using e.g. the subfigure package) that then can be labeled and referenced separately.

If you don't want to/can't do that, you can simulate the subfigures as follows. The \phantomlabel command works like the \label command, but has an additional first argument that gives the suffix to be appended to the number of the figure.

\documentclass{article}
\usepackage{graphicx}
\makeatletter
\newcommand\phantomlabel[2]%
  {\@bsphack
   \protected@write\@auxout{}%
     {\string\newlabel{#2}{{\@currentlabel#1}{\thepage}}}%
   \@esphack
  }
\makeatother
\begin{document}
Figure~\ref{fig:plot} consists of sub-figure~\ref{fig:plot:left_plot},
sub-figure~\ref{fig:plot:right_plot}, and
sub-figure~\ref{fig:plot:somewhere else}.
\begin{figure}
  \includegraphics[width=\textwidth]{example-image-a}
  \caption{This plot has three parts.}\label{fig:plot}
  \phantomlabel{a}{fig:plot:left_plot}
  \phantomlabel{b}{fig:plot:right_plot}
  \phantomlabel{c}{fig:plot:somewhere else}
\end{figure}
\end{document}

enter image description here

  • Thanks! Your solution gives the compiling error Paragraph ended before \Hy@setref@link was complete. which leads me to think that it doesn't work with the hyperlink-package activated. Sorry for not giving a MWE, I wasn't aware if hacking is required. However, I found another workaround (I think). I added some subfigures with width 0pt so they won't take any space at all. I gave them labels and it seems to be working for me. – keyx Oct 25 '16 at 20:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.