4

I need to create table of content in a table format with text wrapping in the subject titles. The page number is currently at the top of each cell. In the rows where the title is wrapped, I need the page number aligned at the bottom. This is my code:

\begin{tabularx}{\linewidth}{ l X l }

  Figure & & Page \\

  1.1.1  &  test text text  text  text  text  text  text  text  text  text  text  text  text  text  text  text  text  text  \dotfill &  10 \\
  1.1.2 & line \dotfill & 12 \\

\end{tabularx}
3
  • Welcome to the site. It helps those trying to help you if you post a complete Minimum Working Example (MWE), starting with \documentclass and ending with \end{document}. Sep 27 '14 at 12:17
  • You need to know how high the X column entry is, which you could do with a \parbox the same width, but you don't know what the width is/will be with tabularx. Sep 27 '14 at 13:21
1

This may be the solution you are looking for, although it is a bit clumsy. You have to include array package to get option b{} for table alignement.

\documentclass{article}
\usepackage{array}

\begin{document}

\begin{tabular}{b{0.1\linewidth}b{0.8\linewidth}p{0.1\linewidth}}

  Figure & & Page \\

  1.1.1 & test text text  text  text  text  text  text  text  text  text  text  text  text  text  text  text  text  text  \dotfill & 10 \\
  1.1.2 & line \dotfill & 12 \\
  1.1.3  &  a lot of text text text text text text text text text text text text text text text text  text  text  text  text  text  text  text  text  text  text  text  text  text  text  text  text  \dotfill &  15 \\

\end{tabular}

\end{document}

The thing you have to do is compile the code above, and look for the lines, where the middle column is on multiple lines:

First compilation

Then insert \newline after the Figure number, so it will move up a line. So in this case the table will look like:

\begin{tabular}{b{0.1\linewidth}b{0.8\linewidth}p{0.1\linewidth}}

  Figure & & Page \\

  1.1.1\newline & test text text  text  text  text  text  text  text  text  text  text  text  text  text  text  text  text  text  \dotfill & 10 \\
  1.1.2 & line \dotfill & 12 \\
  1.1.3\newline\newline  &  a lot of text text text text text text text text text text text text text text text text  text  text  text  text  text  text  text  text  text  text  text  text  text  text  text  text  \dotfill &  15 \\

\end{tabular}

And the final result:

Final

4
  • You probably have a table that is larger than \linewidth due to \tabcolseps between columns.
    – Werner
    Sep 27 '14 at 19:12
  • @Werner yes, I usually forget that :D Set the middle column to 0.65\textwidth and it should be fine. Sep 30 '14 at 19:18
  • 1
    ...or \dimexpr.8\linewidth-6\tabcolsep and precede the tabular with \noindent.
    – Werner
    Sep 30 '14 at 19:20
  • @Werner Fantastic! I always did it manually and now I don't have to. Thanks. Sep 30 '14 at 19:23
3

table with page numbers

\documentclass{article}
\usepackage{tabularx}

\newcommand\DotsPage [1]{\dotfill\rlap{\kern2\tabcolsep #1}&}

\begin{document}
\begin{tabularx}{\linewidth}{ l X l }

  Figure & & Page \\

  1.1.1  &  test text text  text  text  text  text  text  text  text  text
  text  text  text  text  text  text  text  text\DotsPage{10}\\
  1.1.2 & line test text text  text  text  text  text  text  text  text  text
  text  text  text  text  text  text  text  text\DotsPage {12}\\
  1.1.3 & line for comparison\dotfill & 13 
\end{tabularx}
\end{document}
1

Such things are almost always better set as a list than as a table, here just using enumerate but you may want a custom list format (enumitem package might help)

enter image description here

\documentclass{article}

\begin{document}
\def\Dotfill{{\def\hfill{\hskip4em plus 1fill}\dotfill}}



\begin{enumerate}

  \item[1.1.1] test text text  text  text  text  text  text  text  text  text  text  text  text  text  text  text  text  text  \Dotfill  10 
  \item[1.1.2] line \Dotfill  12 
\end{enumerate}

\end{document}

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.