1

When subfigures are added using the package subcaption, the labels generated in the pdf by the showlabels packages are not readable.

The subcaption package is included before showlabels package. How can I correct this?

\usepackage{subcaption}
\usepackage{showlabels}

\begin{figure}
    \centering
    \begin{subfigure}[t]{0.48\linewidth}
        \includegraphics[width=1\linewidth]{plots/membrane/error_H1_rel_1d_100_11_11.pdf}
        \caption{Full RBs}
        \label{fig:membrane_recon_error_full_RB}
    \end{subfigure}
    \begin{subfigure}[t]{0.48\linewidth}
        \includegraphics[width=1\linewidth]{plots/membrane/error_H1_rel_1d_100_11_7.pdf}
        \caption{Full primal RB and truncated dual RB}
        \label{fig:membrane_recon_error_truncated_RB}
    \end{subfigure}
    \caption{Reconstruction error for points in and outside training set}
    \label{fig:membrane_recon_error}
\end{figure}

enter image description here

3
  • 1
    As always on this site please post some minimal code reproducing the issue.
    – campa
    Commented Apr 9, 2021 at 7:55
  • Added minimal code @campa
    – kksagar
    Commented Apr 9, 2021 at 8:37
  • 1
    The problem persists even if you replace subfigure with minipage and remove the subcaption package. Alas, \marginpar doesn't work on floats and \marginnotes will overlap itself. Commented Apr 9, 2021 at 12:48

1 Answer 1

1

This creates a new environment queuelabels which prevents showlabel from overlapping labels within. It uses the url and marginnote packages to format and print the labels.

Note: it takes two runs for the labels to show up.

\documentclass{article}
\usepackage{subcaption}
\usepackage{marginnote}
\usepackage{url}
\usepackage{graphicx}

\let\normallabel=\label
\usepackage{showlabels}

\newsavebox{\labelbox}
\newenvironment{queuelabels}{\def\label##1{\normallabel{##1}%
  \global\setbox\labelbox=\vbox{%
    \hsize=\marginparwidth\raggedright
    \ifvoid\labelbox\else \unvbox\labelbox\vskip\baselineskip\fi
    \url{##1}}}}%
 {\dimen0=\ht\labelbox
  \marginnote{\unvbox\labelbox}[-\dimen0]}

\begin{document}

\begin{figure}
    \begin{queuelabels}
    \centering
    \begin{subfigure}[t]{0.48\linewidth}
        \includegraphics[width=1\linewidth]{example-image-a}
        \caption{Full RBs}
        \label{fig:membrane_recon_error_full_RB}
    \end{subfigure}
    \begin{subfigure}[t]{0.48\linewidth}
        \includegraphics[width=1\linewidth]{example-image-b}
        \caption{Full primal RB and truncated dual RB}
        \label{fig:membrane_recon_error_truncated_RB}
    \end{subfigure}
    \caption{Reconstruction error for points in and outside training set}
    \label{fig:membrane_recon_error}
    \end{queuelabels}
\end{figure}

\end{document}

demo

2
  • Thank you for your answer. But I get the following error: [10] Runaway argument? {\@firstoffive }\fi for two cases of full and truncated dual RB. As \ETC. ! Paragraph ended before \Hy@setref@link was complete. <to be read again>
    – kksagar
    Commented Apr 10, 2021 at 13:29
  • \My@setref@link sounds custom. I can't find it being used in any package I have installed. Commented Apr 11, 2021 at 0:33

You must log in to answer this question.

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