2

I am hyperlinking with

\usepackage{hyperref}

and using the following command to start a Supplementary Information section:

\begin\newcommand{\beginsupplement}{
    \setcounter{section}{0}
    \renewcommand{\thesection}{S\arabic{section}}
    \setcounter{equation}{0}
    \renewcommand{\theequation}{S\arabic{equation}}
    \setcounter{figure}{0}
    \renewcommand{\thefigure}{S\arabic{figure}}}

Before I call \usepackage{hyperref}, the equations, figures, and sections are all numbered 1, 2, ... and link properly to the equations, figures, and sections that they refer to.

After I call \usepackage{hyperref}, the equations, figures, and sections are all numbered S1, S2, ... and the equations and sections link properly. However, the figures inexplicably do not.

My figures are labeled as

\begin{figure*}
    \centering
    \includegraphics[width=8cm]{subfig1.png}
    \includegraphics[width=8cm]{subfig2.png}

    \vspace{0.5cm}

    \includegraphics[width=8cm]{subfig3.png}
    \includegraphics[width=8cm]{subfig4.png}
    \caption{Caption text here.}
    \label{fig:spresults1}
\end{figure*}

The number S3 appears properly when I reference Fig. S3 in the Supplementary Information, but when I click the link, it takes me to Fig. 3 in the main text. However, equations and sections work properly - Eq. S14 links to Eq. S14 not Eq. 14.

\ref itself is working fine, but I think there is an issue in the hyperref package. Does anyone know a way around this?

2
  • 2
    Need a complete example we can try ourselves (a MWE). The hyperref package clashes with several others, any warnings to that effect?
    – vonbrand
    Commented Feb 4, 2020 at 23:41
  • No warnings, but I've managed to find a workaround and posted an answer below. Naturally, I didn't remember I could do such a thing until after I asked the question. Sorry about the lack of a MWE! I'll make a note for next time.
    – BGreen
    Commented Feb 4, 2020 at 23:56

2 Answers 2

2

After some experimentation, I found a solution in creating a new counter. I put it in the last two lines the following block which I use to begin my Supplementary Information.

\newcommand{\beginsupplement}{
    \setcounter{section}{0}
    \renewcommand{\thesection}{S\arabic{section}}
    \setcounter{equation}{0}
    \renewcommand{\theequation}{S\arabic{equation}}
    \setcounter{table}{0}
    \renewcommand{\thetable}{S\arabic{table}}
    \setcounter{figure}{0}
    \renewcommand{\thefigure}{S\arabic{figure}}
    \newcounter{SIfig}
    \renewcommand{\theSIfig}{S\arabic{SIfig}}}

Then I use the new counter in the new figure as

\begin{figure*}
    \centering
    \includegraphics[width=8cm]{subfig1.png}
    \includegraphics[width=8cm]{subfig2.png}

    \vspace{0.5cm}

    \includegraphics[width=8cm]{subfig3.png}
    \includegraphics[width=8cm]{subfig4.png}

    \refstepcounter{SIfig}\label{fig:spresults1}

    \caption{Caption text here.}
\end{figure*}

so that the label is applied to the SIfig counter rather than the caption. Since the target of the label is completely distinct from the figure counter, the references to SI figures properly link back to SI figures.

0

I achieved a similar result as @BGreen without having to use figure* and a separate SIfig counter:

\newcommand{\beginsupplement}{
  ...
  \newcounter{offset}
  \setcounter{offset}{\value{figure}}
  \renewcommand{\thefigure}{S\the\numexpr\value{figure}-\value{offset}\relax}
}

This continues using the same underlying figure counter (so doesn't break hyperref), and just the display gets offset back to 1.

You must log in to answer this question.

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