TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Friends, I'm curious on how to do the following in LaTeX:

Dictionaries have two words on the top of each page, meaning the interval of words to be found on that specific page, e.g.,


In the figure, analyst refers to the lower bound (the first word), and ancillary refers to the upper bound (the last word) in this page.

I was wondering of how we could achieve something similar in LaTeX. Let's say we have the following document:


    \item[adequate] \lipsum[1]
    \item[adhere] \lipsum[2]
    \item[adherence] \lipsum[3]
    \item[adhesion] \lipsum[4]
    \item[adhesive] \lipsum[5]
    \item[adjacent] \lipsum[6]
    \item[adjective] \lipsum[1]
    \item[adjoin] \lipsum[2]
    \item[adjourn] \lipsum[3]
    \item[adjournment] \lipsum[4]
    \item[adjunt] \lipsum[5]
    \item[adjust] \lipsum[6]

My example

For this page, I expect to see both adequate and adhesive in the top of the page (first and last items on the page, respectively). The same rule applies to the rest of the pages. Update: I should've mentioned that I'm curious of an "automatic" way of choosing which words will be set in the page headers. =)

Any ideas?

share|improve this question
Section 10 of the fancyhdr documentation shows how to do this. – Alan Munn Aug 19 '11 at 19:07
@Alan: Interesting, thanks for mentioning. In fact, I was looking for something like an automatic procedure to look which words are the first and last in the current page and then set them in the header. fancyhdr solves the second part (how to put them in there), I wonder how could we solve the first one. =) – Paulo Cereda Aug 19 '11 at 19:16
It's all in there. See my posted answer. – Alan Munn Aug 19 '11 at 21:19
@Alan: my bad, I probably misread the documentation. ;-) – Paulo Cereda Aug 19 '11 at 21:34
up vote 16 down vote accepted

Here's a worked up example based on section 10 of the fancyhdr documentation:

% empty \sectionmark
% create a command to create marks and collapse them if they are identical
{\rightmark} % if equal
{\rightmark--\leftmark}} % if not equal 
% define a wrapper on the description environment to add the marks
% this part is quick and dirty; it would be better to define one's own
% environment to do this, but the basic idea is the same: you need
% to add the \markboth command to each dictionary entry
    \ditem[adequate] \lipsum[1]
    \ditem[adhere] \lipsum[2]
    \ditem[adherence] \lipsum[3]
    \ditem[adhesion] \lipsum[4]
    \ditem[adhesive] \lipsum[5]
    \ditem[adjacent] \lipsum[6]
    \ditem[adjective] \lipsum[1]
    \ditem[adjoin] \lipsum[2]
    \ditem[adjourn] \lipsum[3]
    \ditem[adjournment] \lipsum[4]
    \ditem[adjunt] \lipsum[5]
    \ditem[adjust] \lipsum[6]

output of code

share|improve this answer
Absolutely fantastic, Alan! Thanks a million! =) – Paulo Cereda Aug 19 '11 at 21:31

Your Answer


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.