# How to implement two figure counters with proper hyperlinks in hyperref in latex?

I want to typeset a book with a quiz in it. I want to have two types of figures:

• text figures: These are indexed i, ii (roman)
• quiz figures: These figures are related to the quiz, and should have their proper numbering: 1,2,3...n

I want the quiz figures to be next to each other, not on top of each other, the only way to achieve this is using subfloats. In principle this is possible using custom counters, which gives the proper reference. However, the hyperref package doesn't seem to understand these custom counters.

How do I get the hyperref links to link to the proper figure?

My implementation is as follows:

\documentclass{book}
\usepackage[english]{babel}
\usepackage[]{graphicx}
\usepackage{subfig}
\usepackage{hyperref}

%Counters
\newcounter{textcounter}
\setcounter{textcounter}{0}
\newcounter{quizcounter}
\setcounter{quizcounter}{0}

\begin{document}

\chapter*{Chaptername}

\section*{Introduction}
This is our normal text, where we want to refer to accompanying figures like figure \ref{textfigure1}.

\begin{figure}
\renewcommand{\thesubfigure}{\roman{textcounter}}
\renewcommand{\thefigure}{}
\subfloat[Example textfigure]{\includegraphics[width=0.5\columnwidth]{example_ti.jpg}\label{textfigure1}}
\end{figure}

\section*{Table}
\begin{enumerate}
\end{enumerate}

\section*{quizfigures}
\begin{figure}
\renewcommand{\thesubfigure}{\arabic{quizcounter}}
\renewcommand{\thefigure}{}
\subfloat[Example quizfigure 1]{\includegraphics[width=0.5\columnwidth]{example_q1.jpg}\label{quizfigure1}}
\end{figure}

\newpage

\begin{figure}
\renewcommand{\thesubfigure}{\arabic{quizcounter}}
\renewcommand{\thefigure}{}
\subfloat[Example quizfigure 2]{\includegraphics[width=0.5\columnwidth]{example_q2.jpg}\label{quizfigure2}}
\subfloat[Example quizfigure 3]{\includegraphics[width=0.5\columnwidth]{example_q3.jpg}\label{quizfigure3}}
\end{figure}

\end{document}

-

## migrated from stackoverflow.comApr 13 '13 at 18:40

This question came from our site for professional and enthusiast programmers.

You don't have to use custom counters, you can use the built-in counter of the subcaption package. This is a replacement for the deprecated subfig package.

You can use

\captionsetup{labelformat=empty,labelsep=none}
\renewcommand{\thefigure}{}


to supress the labels of the figures themselves and name the subfigures as if they were figures.

To use the built-in counter with roman numerals, you can use

\renewcommand{\thesubfigure}{\roman{subfigure}}


In order to continue the label count of the subfigures in between separate figure environments, you should only use caption{} in the last figure.

\documentclass{book}
\usepackage[english]{babel}
\usepackage[]{graphicx}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{hyperref}

\captionsetup{labelformat=empty,labelsep=none}
\renewcommand{\thefigure}{}

\begin{document}

\chapter*{Chaptername}

\section*{Introduction}
This is our normal text, where we want to refer to accompanying figures like figure \ref{textfigure1}.

\begin{figure}
\renewcommand{\thesubfigure}{\roman{subfigure}}

\begin{subfigure}{6cm}
\caption{Example textfigure}
\label{textfigure1}
\end{subfigure}

\caption{}
\label{test}
\end{figure}

\section*{Table}
\begin{enumerate}
\end{enumerate}

\section*{quizfigures}
\begin{figure}
\begin{subfigure}{3cm}
\caption{Example quizfigure 1}
\label{quizfigure1}
\end{subfigure}
\end{figure}

\newpage

\begin{figure}
\begin{subfigure}{3cm}
\caption{Example quizfigure 2}
\label{quizfigure2}
\end{subfigure}
\begin{subfigure}{3cm}
\caption{Example quizfigure 3}
\label{quizfigure3}
\end{subfigure}
\caption{}
\end{figure}

\end{document}

-