Document Classesmakeindex making indexes in more than two columns?

Information and discussion about specific document classes and how to create your own document classes.
User avatar
Bozack
Posts: 117
Joined: Wed Feb 06, 2008 4:21 pm

makeindex making indexes in more than two columns?

Post by Bozack »

When you use makeindex to make an index at the end of your document (via \printindex), it automatically makes a two-column index. -Is there any way to make this another number of columns, like only one, or three? :|
Last edited by Bozack on Sat Jun 06, 2009 9:22 am, edited 1 time in total.
OS, LaTeX-system, editor: Arch Linux 64bit, TeXlive, Kile | Windows 10 Professional 64bit, MikTeX 4.9, TeXnicCenter 2.02 64bit

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

makeindex making indexes in more than two columns?

Post by localghost »

You could try to use the multicol package and put the index into a multicols environment.

Code: Select all

\begin{multicols}{3}
  \printindex
\end{multicols}
I don't know if it works, because I didn't test it.


Best regards
Thorsten¹
User avatar
Bozack
Posts: 117
Joined: Wed Feb 06, 2008 4:21 pm

makeindex making indexes in more than two columns?

Post by Bozack »

localghost wrote:You could try to use the multicol package
Nopes, it doesn't do the right thing.. It just ends up with sending the section-header to the end of the document and putting the columns in weird ways..:

Code: Select all

\addcontentsline{toc}{section}{Indeks}
\begin{multicols}{3}
	{\normalsize{ \printindex }}
\end{multicols}
produces:
Image

There must be some problem with the multicols package coorporating with the makeindex package, since the makeindex normally makes two-column output?
OS, LaTeX-system, editor: Arch Linux 64bit, TeXlive, Kile | Windows 10 Professional 64bit, MikTeX 4.9, TeXnicCenter 2.02 64bit
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

makeindex making indexes in more than two columns?

Post by localghost »

I remember a discussion we had a few days ago in our german forum about a very similar topic. Herbert Voss (the author and maintainer of many additional PSTricks package and "Math mode") offered a solution that also uses the multicol package. I hope he doesn't mind me providing this solution here.

Code: Select all

\makeatletter
\renewenvironment{theindex}{%
  \columnseprule \z@
  \columnsep 35\p@
  \idx@heading%
  \index@preamble\par\nobreak
  \thispagestyle{\indexpagestyle}\parindent\z@
  \setlength{\parskip}{\z@ \@plus .3\p@}%
  \setlength{\parfillskip}{\z@ \@plus 1fil}%
  \begin{multicols}{2}%
  \let\item\@idxitem
}{\end{multicols}\clearpage}   
\makeatother
Put this new definition of the theindex environment in your preamble. Don't ask me what this code exactly does. Beside usual LaTeX commands it uses some internal registers to get a proper formatting. According to some reports it works fine. Perhaps you can report here about success.
User avatar
Juanjo
Posts: 657
Joined: Sat Jan 27, 2007 12:46 am

makeindex making indexes in more than two columns?

Post by Juanjo »

I just would like to remark that the solution provided by localghost will work with the Koma-script classes (scrartcl, scrbook...), not with the standard ones (article, book...) or with memoir. Bozack, if you are using the standard ones, ask again.
The CTAN lion is an artwork by Duane Bibby. Courtesy of www.ctan.org.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

makeindex making indexes in more than two columns?

Post by localghost »

Juanjo wrote:I just would like to remark that the solution provided by localghost will work with the Koma-script classes (scrartcl, scrbook...), not with the standard ones (article, book...) or with memoir. [...]
Oh, that's something I didn't take into account. Perhaps it works when replacing \indexpagestyle (a macro from KOMA Script) by plain in the above given code.
User avatar
Bozack
Posts: 117
Joined: Wed Feb 06, 2008 4:21 pm

Re: makeindex making indexes in more than two columns?

Post by Bozack »

Unfortunately I'm using the article class, so that won't be the solution..

I'll try later today after lectures anyway though :)
OS, LaTeX-system, editor: Arch Linux 64bit, TeXlive, Kile | Windows 10 Professional 64bit, MikTeX 4.9, TeXnicCenter 2.02 64bit
User avatar
Juanjo
Posts: 657
Joined: Sat Jan 27, 2007 12:46 am

makeindex making indexes in more than two columns?

Post by Juanjo »

The following code may work with the article class:

Code: Select all

\usepackage{multicol}
\makeatletter
\renewenvironment{theindex}
  {\if@twocolumn
      \@restonecolfalse
   \else
      \@restonecoltrue
   \fi
   \setlength{\columnseprule}{0pt}
   \setlength{\columnsep}{35pt}
   \begin{multicols}{3}[\section*{\indexname}]
   \markboth{\MakeUppercase\indexname}%
            {\MakeUppercase\indexname}%
   \thispagestyle{plain}
   \setlength{\parindent}{0pt}
   \setlength{\parskip}{0pt plus 0.3pt}
   \relax
   \let\item\@idxitem}%
  {\end{multicols}\if@restonecol\onecolumn\else\clearpage\fi}
\makeatother
It will generate an index with three columns. Change the mandatory argument of the multicols environment to set a different number of columns. You may also want to reduce the space between columns: modify the value assigned to \columnsep. If you find that indentation of the index entries are too big, you may also want to adapt the lengths in the following lines which appear in article.cls:

Code: Select all

\newcommand\@idxitem{\par\hangindent 40\p@}
\newcommand\subitem{\@idxitem \hspace*{20\p@}}
\newcommand\subsubitem{\@idxitem \hspace*{30\p@}}
\newcommand\indexspace{\par \vskip 10\p@ \@plus5\p@ \@minus3\p@\relax}
Copy the corresponding line between \makeatletter and \makeatother, change the length and replace \newcommand by \renewcommand.
The CTAN lion is an artwork by Duane Bibby. Courtesy of www.ctan.org.
User avatar
Bozack
Posts: 117
Joined: Wed Feb 06, 2008 4:21 pm

makeindex making indexes in more than two columns?

Post by Bozack »

Juanjo wrote:The following code may work with the article class
That turned out just as I was hoping for, thank you so much :)
OS, LaTeX-system, editor: Arch Linux 64bit, TeXlive, Kile | Windows 10 Professional 64bit, MikTeX 4.9, TeXnicCenter 2.02 64bit
swiftarrow
Posts: 1
Joined: Sat Jan 16, 2010 12:41 pm

makeindex making indexes in more than two columns?

Post by swiftarrow »

Hey, this post above was a life-saver for me! I've registered just to reply!

I'm using book class, and only wanted two columns, so what I did was:

Code: Select all

\usepackage{multicol}
\makeatletter
\renewenvironment{theindex}
  {\if@twocolumn
      \@restonecolfalse
   \else
      \@restonecoltrue
   \fi
   \setlength{\columnseprule}{0pt}
   \setlength{\columnsep}{35pt}
   \begin{multicols}{2}[\chapter*{\indexname}]		%Adjust the 2 for more columns
   \markboth{\MakeUppercase\indexname}%
            {\MakeUppercase\indexname}%
   \thispagestyle{plain}
   \setlength{\parindent}{0pt}
   \setlength{\parskip}{0pt plus 0.3pt}
   \relax
   \let\item\@idxitem}%
  {\end{multicols}\if@restonecol\onecolumn\else\clearpage\fi}
\makeatother
Furthermore, though I didn't need to adjust the spacing, I did want the top level entries to be in bold. For that I did this:

Code: Select all

\makeatletter
\renewcommand\@idxitem{\scriptsize\bfseries\par\hangindent 40\p@}			%Makes all the index entries small,  bold
\renewcommand\subitem{\scriptsize\@idxitem \normalfont\hspace*{20\p@}}			%Makes subitems small, normal
\renewcommand\subsubitem{\scriptsize\@idxitem \normalfont\hspace*{30\p@}}		%Makes subsubitems small, normal
\makeatother
And to help people find this, allow me to put in some keywords for search engines: I was searching for ways to alter the display of the index in latex, or to make space above the index chapter head. Latex index is impossible to find. Let's get some Hits!

If anyone has the knowledge or the drive, I think that this could be built into a package to address a sore vacancy!
Post Reply