3

I'm trying to create a form that contains a series of test instructions, each of which are represented as minipages and take up between 1/3 - 1/2 of a standard A4 page. What I'd like is to be able to display the number of tests on a page within the foot of each page.

I've created a counter that increments whenever a test is added and is reset whenever the page counter increments. However, I'm finding that the test counter increments even if the test ends up on the next page due to inadequate space. Is there a way that I can make the counter report the correct number of tests on each page?

Included is a MWE:

\documentclass[10pt,a4paper]{article}   

\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{fancyhdr}

\rfoot{\large{$\dfrac{}{\arabic{PageTestCounter}}$}}

\newcounter{PageTestCounter}[page]

\newcommand{\addTest}[1]{%
\stepcounter{PageTestCounter}
Test #1:\hspace{1cm}$\square$
\vspace{25\baselineskip}
}

\begin{document}

\pagestyle{fancy}

\addTest{1}

\addTest{2}

\addTest{3}

\end{document}

The output from the MWE:

enter image description here

4

You should use a \mark command e.g. with the extramarks package:

\documentclass[10pt,a4paper]{article}
\usepackage{extramarks}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{fancyhdr}

\rfoot{\large{$\dfrac{}{\lastxmark}$}}

\usepackage{perpage}
\newcounter{PageTestCounter}
\MakePerPage{PageTestCounter}

\newcommand{\addTest}[1]{%
\stepcounter{PageTestCounter}%
Test #1:\extramarks{}{\arabic{PageTestCounter}}\hspace{1cm}$\square$    
\vspace{25\baselineskip}%
}

\begin{document}

\pagestyle{fancy}

\addTest{1}

\addTest{2}

\addTest{3}

\end{document}

You can also use the normal \markboth, but probably you will need it for section.

  • That's almost got it, thanks! However, the counter doesn't seem to be resetting properly; I should be getting "/2" and "/1" on the first and second pages respectively, but instead I get "/2" and "/3". – Tagc Aug 29 '14 at 9:44
  • Sorry I only looked at the footer code and didn't realize the problem with the counter (needs two compilations). You can reset the counter with the perpage package, see my edited code. – Ulrike Fischer Aug 29 '14 at 10:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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