1

I want to label my figures like this:

\label{fig:scatterysX}

Where is x a number which changes to some kind of step counter (numeric). I tried \newcounter{foo}, \stepcounter{foo} in the loop, and \value{foo} on x but this doesn't seem to work.

Please provide a working example.

1
  • Ok thanks for your constructive remark. Luckily Herbert has provided a working example making this a question which could support the broader community.
    – BigChief
    Aug 6, 2014 at 22:33

1 Answer 1

3
\documentclass{article}
\usepackage{varioref}
\newcounter{foo}\setcounter{foo}{0}
\let\endF\endfigure
\renewcommand\endfigure{%
  \expandafter\label\expandafter{fig:scatterys\thefoo}\endF\stepcounter{foo}}
\begin{document}

\begin{figure}[!htb]foo\caption{bar}\end{figure}\clearpage
\begin{figure}[!htb]foo\caption{bar}\end{figure}\clearpage
\begin{figure}[!htb]foo\caption{bar}\end{figure}\clearpage
\begin{figure}[!htb]foo\caption{bar}\end{figure}

see Figure~\vref{fig:scatterys0} or Figure~\vref{fig:scatterys1}
or Figure~\vref{fig:scatterys2} or Figure~\vref{fig:scatterys3}
\end{document}

enter image description here

If you do not something special with the \thefoo then the \expandafter are not really needed.

9
  • Does not really work as expected, the figures are in the appendix. When adding your code i get the output: See Figure Appendix A - on page 5, instead of See Figure 1 on page 5
    – BigChief
    Aug 5, 2014 at 14:38
  • Any suggestions on how to let this work..???
    – BigChief
    Aug 5, 2014 at 14:49
  • 1
    Sigh ... Then simply use \ref instead of \vref which i used only for the demonstration. And, of course redefine \thefoo
    – user2478
    Aug 5, 2014 at 14:55
  • 1
    I need a complete minimal example to see what configuration you are using.
    – user2478
    Aug 5, 2014 at 15:49
  • 1
    with configurationI meant the settings of your document, eg the documentationclass. YXour link doesn't help it shows no complete example.
    – user2478
    Aug 5, 2014 at 16:24

You must log in to answer this question.

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