0

I'm trying to write a customized table of contents, let's say one with three values per row, and displayed in two columns, like this:

enter image description here

I understand the best option would be to use tabular to have the values aligned. However, with tabular, I don't seem to be able to break the toc into two columns (like in the example above).

Or I could make a six-column table, but I'd have to manually manage the column break and eventual page breaks.

Any recommendation?

Here's a starter code:

\documentclass{article}
\usepackage{multicol}
\usepackage{tabularx}
\setlength{\columnseprule}{0.4pt}

\begin{document}

\begin{multicols}{2}
\begin{tabularx}{\columnwidth}{rXr}
\textbf{p} & \textbf{title} & \textbf{date} \\
1 & Introduction & 01/01 \\
22 & Methodology & 01/15 \\
333 & Results & 02/01 \\
4 & Conclusion & 02/15 \\
5 & Discussion & 03/01 \\
6 & Appendix A & 03/15 \\
7 & Appendix B & 04/01 \\
8 & Bibliography & 04/15 \\
\end{tabularx}
\end{multicols}

\end{document}
2
  • Why not a column specification of {rXr|rXr}? The more interesting question would be if someone can make \tableofcontents do this automatically.
    – Teepeemm
    Apr 3, 2023 at 1:44
  • In order to do it automatically, you could add the date with something similar to this answer: tex.stackexchange.com/questions/689604/… . And then just add \addtocontents{toc}{\protect\begin{multicols}{2}} at the beginning of the document, and \addtocontents{toc}{\protect\end{multicols}} at the end of it, to typeset the toc on two columns (of course, with multicol package loaded) Sep 4, 2023 at 10:03

1 Answer 1

0

I designed something. I really just needed tabular to keep the three elements aligned, so instead I wrote a command that inserts the proper spacing between them.

\documentclass{article}
\usepackage{multicol}

\setlength{\columnseprule}{0.4pt}  % Column separator rule
\setlength{\columnsep}{2em}  % Distance between columns

\newlength{\maxspace}
\newlength{\negspace}

\newcommand{\tocline}[3]
{
    \settowidth{\maxspace}{999}  % Get the width of the wider element in the first column
    \settowidth{\negspace}{#1}  % Get width of current element in the first column
    \noindent
    \hspace{\maxspace}\hspace{-1\negspace}  % Advance by the maximum width possible minus the current width
    #1  % Insert first element
    \hspace{0.5em}  % Advance by a fixed amount
    #2  % Insert second element
    \hfill  % Place the third element in the far right
    #3\par  % Insert third element and end paragraph
}

\begin{document}
    
\begin{multicols}{2}
    \tocline{p}{title}{date}
    \tocline{1}{Introduction}{01/01}
    \tocline{22}{Methodology}{01/01}
    \tocline{333}{Results}{01/01}
    \tocline{4}{Conclusion}{01/01}
    \tocline{6}{Appendix}{01/01}
\end{multicols}

\end{document}

Result:

enter image description here

You must log in to answer this question.

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