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'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

share|improve this question

1 Answer 1

up vote 4 down vote accepted

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.

share|improve this answer
    
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 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 at 10:48
    
Awesome work, thanks. –  Tagc Aug 29 at 11:17

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.