16

I am writing an article in LaTeX 2e with \documentclass[twocolumn]{article}, including an index. The document prelude includes \usepackage{makeidx} and the \makeindex command. At the point where I want the index to print I say \printindex. The indexing operations all work perfectly. However, when the document is formatted, a page break is inserted both before and after the index. I want to eliminate both page breaks. I assume that \printindex calls \include, which performs \clearpage, though I don't really know that. How can I eliminate the two page breaks?

1
  • I have a solution: Change theindex environment in filename.ind to trivlist, then use \input{filename.ind} instead of \printindex. That feels clunky, and requires manual intervention each time I make the document, but it works. Is there a better way?
    – user448810
    Commented Jul 22, 2011 at 21:35

2 Answers 2

15

The theindex environment is defined in article.cls as follows:

\newenvironment{theindex}
               {\if@twocolumn
                  \@restonecolfalse
                \else
                  \@restonecoltrue
                \fi
                \twocolumn[\section*{\indexname}]%
                \@mkboth{\MakeUppercase\indexname}%
                        {\MakeUppercase\indexname}%
                \thispagestyle{plain}\parindent\z@
                \parskip\z@ \@plus .3\p@\relax
                \columnseprule \z@
                \columnsep 35\p@
                \let\item\@idxitem}
               {\if@restonecol\onecolumn\else\clearpage\fi}

The line

\twocolumn[\section*{\indexname}]

forces a new page (\twocolumn does it) and the line

\if@restonecol\onecolumn\else\clearpage\fi

also forces a new page (\onecolumn and \clearpage handle this).

To avoid this behaviour you can redefine the theindex environment; since you are using the twocolumn class option, this redefinition can be done by adding the following lines to the preamble of your document:

\makeatletter
\renewenvironment{theindex}
               {\section*{\indexname}%
                \@mkboth{\MakeUppercase\indexname}%
                        {\MakeUppercase\indexname}%
                \thispagestyle{plain}\parindent\z@
                \parskip\z@ \@plus .3\p@\relax
                \columnseprule \z@
                \columnsep 35\p@
                \let\item\@idxitem}
               {}
\makeatother

A little working example:

\documentclass[twocolumn]{article}
\usepackage{makeidx}

\makeatletter
\renewenvironment{theindex}
               {\section*{\indexname}%
                \@mkboth{\MakeUppercase\indexname}%
                        {\MakeUppercase\indexname}%
                \thispagestyle{plain}\parindent\z@
                \parskip\z@ \@plus .3\p@\relax
                \columnseprule \z@
                \columnsep 35\p@
                \let\item\@idxitem}
               {}
\makeatother

\makeindex

\begin{document}

A\index{A}B\index{B}
\printindex
some text

\end{document}

which produces

enter image description here

0
4
  1. While my answer given in 2012 worked with my system in 2012, it is broken with TeX Live 2022 (for an index with two pages, the first page does not show up at all). I didn't track down where what when why broke and how to fix it.

  2. @Daniel Harbour: About the second column starting at the top instead of below the "Index" (section title): Take Gonzalo Medina's answer, add a \usepackage{afterpage} and after \section*{\indexname}% add the two lines \edef\idxtmp{\the\pagetotal}% and \afterpage{\vspace*{\idxtmp}}%. \pagetotal is the vertical space LaTeX already used up (in that column). \afterpage in two-column-mode means "\aftercolumn", i.e. after the end of the first column blank vertical space is issued. (Instead of \edef maybe work with a real length and see whether you need to add or remove some vertical space for optimal visual appearance of both columns.)


The answer of Gonzalo Medina is great for documents which use the twocolumn class-option (as requested by the OP; already gave +1 for Gonzalo Medina's answer).

For "overkill" (http://tex.blogoverflow.com/2011/10/overkill-is-a-good-thing/; and because this is way too long for a comment and comments cannot be formated like this) it is possible to handle this for one- and two-column documents (I had this problem for a one-column document and was able to solve it because of Gonzalo Medina's answer):

\documentclass{article}
%\documentclass[twocolumn]{article}
% both work
\usepackage{makeidx}

\makeatletter

% * define a `\twoidxcolumn` based on `\twocolumn`:
\def\twoidxcolumn{%
%\clearpage
\global\columnwidth\textwidth
\global\advance\columnwidth-\columnsep
\global\divide\columnwidth\tw@
\global\hsize\columnwidth
\global\linewidth\columnwidth
\global\@twocolumntrue
\global\@firstcolumntrue
\col@number \tw@
%\@ifnextchar [\@topnewpage
\@floatplacement
}


% * define a `\oneidxcolumn` based on `\onecolumn`:
\def\oneidxcolumn{%
%\clearpage
\global\columnwidth\textwidth
\global\hsize\columnwidth
\global\linewidth\columnwidth
\global\@twocolumnfalse
\col@number \@ne
\@floatplacement}


% * replace `\twocolumn` in `theindex` by `\twoidxcolumn`, remove the `[` `]`, 
% and replace `\if@restonecol\onecolumn\else\clearpage\fi` by 
% `\if@restonecol\oneidxcolumn\else\relax\fi`:
\renewenvironment{theindex}
  {\if@twocolumn
     \@restonecolfalse
   \else
     \@restonecoltrue
   \fi
   \twoidxcolumn \section*{\indexname}%
   \@mkboth{\MakeUppercase\indexname}%
           {\MakeUppercase\indexname}%
   \thispagestyle{plain}\parindent\z@
   \parskip\z@ \@plus .3\p@\relax
   \columnseprule \z@
   \columnsep 35\p@
   \let\item\@idxitem}
  {\if@restonecol\oneidxcolumn\else\relax\fi}
\makeatother

\makeindex

\begin{document}

A\index{A} B\index{B} Lorem ipsum dolor sit amet, consectetuer adipiscing elit. 
Ut purus elit, vestibulum ut, placerat ac, adipiscing vitae, felis. 
\par\printindex 
% Note the `\par` before `\printindex`! Without this, the paragraph
% before `\printindex` will be in twocolumn mode, too. 
% (An empty line before `\printindex` works, too, of course.)
Curabitur dictum gravida mauris. Nam arcu libero, nonummy eget, consectetuer id, 
vulputate a, magna. Donec vehicula augue eu neque. Pellentesque habitant morbi 
tristique.

\end{document}
2
  • 1
    One facet of this solution (which is otherwise very nice) is that, on the opening page of the index, the righthand column starts at the top of the page. I think it would look neater if the top entry of the right column were aligned with the top entry of the left column. Is that possible? Thanks. (Sorry I can't post a pic in this comment.) Commented Mar 27, 2014 at 20:16
  • @DanielHarbour Please see updated answer.
    – Stephen
    Commented Nov 26, 2022 at 18:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .