11

How does one set the value of a counter to the value obtained from a \ref{} command?

I am using the xr package to access labels from another document; I want to add the value of a \ref{} to a counter in my current document.

I tried \setcounter{newcount}{\value{\ref{oldlabel}}} but that doesn't work.

0

1 Answer 1

15

This is a job for the \setcounterref command from the refcount package:

\documentclass{article}
\usepackage{refcount}

\newcounter{newcount}

\begin{document}

\begin{figure}\caption{test}\label{ref:A}\end{figure}
\setcounterref{newcount}{ref:A}
The value of \texttt{newcount} is \thenewcount

\end{document}

enter image description here

1
  • That's perfect. I had forgotten about that package. Thanks.
    – GregH
    Commented Jun 20, 2013 at 14:11

You must log in to answer this question.

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