[texhax] First and last value of custom counter in header

Heiko Oberdiek heiko.oberdiek at googlemail.com
Mon May 10 01:06:41 CEST 2010


On Sun, May 09, 2010 at 02:08:09PM +0200, Aleksandar Zec wrote:

> I think that what I am going to ask is not answered in any archived
> post I could find regarding "dictionary-style headers".
> 
> I have pages typed in multicols{2}, full of little items numbered with
> a custom counter (which is increased by 1 after each item):
> 
> \thecnt text     \thecnt text
> \thecnt text     \thecnt text
> \thecnt text     \thecnt text
> \thecnt text     \thecnt text
> 
> How can I produce a fancyhdr string that shows the first and the last
> \thecnt that appeared on the current page, in the form (first--last),
> like this:
> 
> first--last
> --------------------------
> \thecnt text     \thecnt text
> \thecnt text     \thecnt text
> \thecnt text     \thecnt text
> \thecnt text     \thecnt text

Classical case for a marks register. Example that uses an additional
marks register provided by e-TeX:

\documentclass{article}
\usepackage{etex}
\newmarks\dictmark
\usepackage{fancyhdr}
\fancyhead{}
\fancyhead[C]{\firstmarks\dictmark--\botmarks\dictmark}
\fancyfoot{}
\fancyfoot[C]{page \thepage}
\pagestyle{fancy}

\newcounter{cnt}
\newcommand*{\TheCnt}{%
  \stepcounter{cnt}%
  \marks\dictmark{\thecnt}%
  \thecnt. %
}
\begin{document}
\TheCnt text
\TheCnt text
\newpage
\TheCnt text
\TheCnt text
\TheCnt text
\end{document}

Yours sincerely
  Heiko Oberdiek


More information about the texhax mailing list