Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
\addtocounter{textcounter}{1}
\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}
\item Question one, asking questions about quizfigure \ref{quizfigure1}.
\item Question two, asking questions about quizfigure \ref{quizfigure2} , with more info in textfigure \ref{textfigure1}.
\end{enumerate}

\section*{quizfigures}
\begin{figure}
\renewcommand{\thesubfigure}{\arabic{quizcounter}}
\renewcommand{\thefigure}{}
\addtocounter{quizcounter}{1}
\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}{}
\addtocounter{quizcounter}{1}
\subfloat[Example quizfigure 2]{\includegraphics[width=0.5\columnwidth]{example_q2.jpg}\label{quizfigure2}}
\addtocounter{quizcounter}{1}
\subfloat[Example quizfigure 3]{\includegraphics[width=0.5\columnwidth]{example_q3.jpg}\label{quizfigure3}}
\end{figure}


\end{document}
share|improve this question

migrated from stackoverflow.com Apr 13 '13 at 18:40

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

1 Answer 1

up vote 2 down vote accepted

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}
\item Question one, asking questions about quizfigure \ref{quizfigure1}.
\item Question two, asking questions about quizfigure \ref{quizfigure2} and \ref{quizfigure3} , with more info in textfigure \ref{textfigure1}.
\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}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.