# Index shouldn't start new page

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?

-

## migrated from stackoverflow.comJul 23 '11 at 1:59

This question came from our site for professional and enthusiast programmers.

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 Jul 22 '11 at 21:35

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

-
That's exactly what I needed. Thanks a lot! –  user13744 Apr 19 '12 at 11:19

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\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}

-
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.) –  Daniel Harbour Mar 27 '14 at 20:16
@DanielHarbour: I saw your comment, but currently several pressing projects don't leave time to look at the code - I hope to return to it later this year, I'm sorry! –  Stephen Jun 25 '14 at 8:56