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.

1
  • 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!
    – user30471
    Commented May 28, 2015 at 8:28

2 Answers 2

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.

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?)

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .