My table was aligned very nicely, until I started trying to add indices to my book. The index at the end is loading fine, but the tables where I used the \index
method inside of lose their vertical alignment. Can anyone help? Below is example code and result
\documentclass{book}
\usepackage[paperwidth=6in, paperheight=9in, margin=0.8in]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{titlesec}
\usepackage{etoolbox}
\usepackage{imakeidx}
\makeindex
\makeatletter
\patchcmd\chapter{\thispagestyle}{\global\c@footnote\z@\thispagestyle}{}{}
\makeatother
\titleformat{\chapter}{\normalfont\huge}{\thechapter.}{20pt}{\huge\it}
\renewcommand{\chaptermark}[1]{\markboth{}{\sffamily #1}}
\begin{document}
\frontmatter
\maketitle
\tableofcontents
\mainmatter
\chapter{Timeline of astronomers and astrologers}
\begin{tabular}{rp{0.4\linewidth}p{0.4\linewidth}}
\textbf{Year} & \textbf{Original text} & \textbf{Translation} \\
1990BC & \index{Zoroastres}Zoroastres Bactrianorum Rex & \index{Zoroaster}Zoroaster, king of Bactria \footnotemark \\
1590BC & \index{Prometheus}Prometheus Atlantis frater & Prometheus, brother of Atlas \\
1580BC & \index{Atlas}Atlas Rex Mauritaniae & Atlas, King of Mauretania \footnotemark \\\index{Mercury}Mercury the greater \\
\end{tabular}
\printindex
\end{document}
Before I added the \index
commands, the lines were vertically aligned and not going off the right side of the page.
Best Answer
Starting a paragraph (in the second/third column) with an
\index
(which technically doesn't set anything) is the cause of this issue. Instead of usingconsider using
This shift in
\index
is not an issue in this setup as thetabular
will keep the content on the same page - necessary when thinking about indices pointing to a specific page. If you had content starting a paragraph that could span a page boundary, then useinstead.
\leavevmode
(or just\mbox{}
) will initiate horizontal mode so the paragraph can start.