0

For each figures in my document, I need to have corresponding supplementary figures: e.g. for figure 1, I might have figure 1 – S1, figure 1 – S2, and so on.

I use renewcommand to get these names. Within the new definition of \thefigure, I simply have a \ref* pointing to the main figure to get the first number. All is well.

But the links for the supplementary figures point to the wrong places. If I try to redefine \theHfigure, I get all sorts of weird errors.

\documentclass{article}
\usepackage{hyperref}
\usepackage{cleveref}

\begin{document}

\section*{Main text}

This is my \cref{figure}.

\begin{figure}[h!]
  %...
  \caption{Some figure.}
  \label{figure}
\end{figure}

\section*{Supplement}

This figure concerns the \cref{figure} and is the \cref{suppfigure}.

\setcounter{figure}{0}
\renewcommand\thefigure{\ref*{figure} -- S\arabic{figure}}
\renewcommand{\theHfigure}{S{\thefigure}}

\begin{figure}[h!]
  %...
  \caption{Juicy details.}
  \label{suppfigure}
\end{figure}

\end{document}

Output:

(...) ! Argument of \Hy@tempa has an extra }. \par l.382 }

The error seems to be caused by the \ref* within the new definition of \thefigure, because it works fine if I remove it.

Is there a way to fix this?

4
  • Welcome to TeX.SE. Please tell us more about structure of the supplementary figures. E.g., are they supposed be independent, standalone floats, or will they always occur on the same page as the "main" figure? – Mico Mar 1 at 8:10
  • \renewcommand{\theHfigure}{S{\arabic{figure}}}. – Ulrike Fischer Mar 1 at 8:11
  • @Mico The appear in the appendix, so on a different page. – cheersmate Mar 1 at 8:16
  • @UlrikeFischer That works, thanks a lot! Can you post an answer so I can accept? – cheersmate Mar 1 at 8:16
2

Your definition of \theHfigure is too complicated. As it contains a \ref command, hyperref can't build a name with it. All \theH... definition need to follow two rules: they should be simple (expandable) and lead to something unique. So use e.g.

\renewcommand{\theHfigure}{S{\arabic{figure}}}

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.