1

Is there a simple way to create a table of contents like table?

In detail i want the same layout like the toc, the same width and especially the filling of the white space with dots, but with a tabular as content.

So far I tried to adopt the regular tabular and adjust the alignment and column width, but I fail at filling the white spaces with dotted lines.

gman
  • 1,807
lenxn
  • 373
  • Welcome to TeX.SX! It is easier to help you if you add a minimal working example that takes the form \documentclass{...}\usepackage{....}\begin{document}...\end{document} in order to show us what you have tried. If possible, it should compile and have the minimum amount of code needed to illustrate your problem. This makes it much easier for people to help you - and much more likely that they will! –  May 28 '15 at 08:28

2 Answers2

1
\documentclass{article}
\usepackage{tabularx}

\makeatletter
\newcommand*{\tocdotfill}{%
  \leaders\hbox{%
    $\m@th \mkern \@dotsep mu\hbox{.}\mkern \@dotsep mu$%
  }\hfill\kern\z@
}
\makeatother

\begin{document}
\noindent
\begin{tabularx}{\linewidth}{lXr}
A & Hello world \dotfill & 1\\
B & Foobar \tocdotfill & 2\\
\end{tabularx}
\end{document}

Result

The important issue is that a skip specification is removed at the end of a table cell via \unskip. \dotfill has added a \kern\z@ at the end to prevent this.

Macro \tocdotfill uses the same code as \dottedtocline, which is used in the table of contents. Also \kern\z@ is appended to prevent from "unskipping". Also other things like \null, an empty \hbox, can be used for this purpose.

Heiko Oberdiek
  • 271,626
0

The dotted lines are made with \dotfill. A table with tabularx could be:

\documentclass{article}
\usepackage{tabularx}
\begin{document}
\begin{tabularx}{\textwidth}{ccX@{}l}
    test1 & test & test \dotfill & [A] \\
    test2 & test & test \dotfill & [V] \\
\end{tabularx}
\end{document}

To change the spacing of the dots you can redefine the command (see: How to change dot spacing in \dotfill?)