21

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.,

Dictionary

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:

\documentclass{article}
\usepackage{multicol}
\usepackage{enumerate}
\usepackage{lipsum}

\begin{document}
\begin{multicols}{2}
\begin{description}
    \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]
\end{description}
\end{multicols}
\end{document}

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?

  • 3
    Section 10 of the fancyhdr documentation shows how to do this. – Alan Munn Aug 19 '11 at 19:07
  • 1
    @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
  • 1
    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
16

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

\documentclass[twoside]{article}
\usepackage{multicol}
\usepackage{ifthen}
\usepackage{fancyhdr}
\usepackage{enumerate}
\usepackage{lipsum}
% empty \sectionmark
\renewcommand{\sectionmark}[1]{}
% create a command to create marks and collapse them if they are identical
\newcommand{\mymarks}{%
\ifthenelse{\equal{\leftmark}{\rightmark}}
{\rightmark} % if equal
{\rightmark--\leftmark}} % if not equal 
\fancyhead[LE,RO]{\mymarks} 
\fancyhead[LO,RE]{\thepage}
% 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
\def\ditem[#1]{\markboth{#1}{#1}\item[#1]}
\pagestyle{fancy}
\begin{document}
\begin{multicols}{2}
\begin{description}
    \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]
\end{description}
\end{multicols}
\end{document}

output of code

  • Absolutely fantastic, Alan! Thanks a million! =) – Paulo Cereda Aug 19 '11 at 21:31

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.