0

How can I test whether I'm on the left or right column of multicol?

I am trying to build a two-column table of contents, where formatting depends on wether the entry is on the left or right column

Here's a mockup (code below).

enter image description here

\documentclass{article}
\usepackage{multicol}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{multicols}
\setlength{\PreviewBorder}{1ex}
% mock TOC commands ===================================
\newcommand{\myStrut}{%
  \rule[-.3\baselineskip]{0pt}{1.4\baselineskip}}

\newcommand{\myTocEntryLeft}[2]{%
  \hfill\myStrut\textbf{\large #2} \ #1\par}

\newcommand{\myTocEntryRight}[2]{%
  #1 \ \myStrut\textbf{\large #2}\hfill\par}

\newcommand{\myTocEntry}[2]{%
  \myTocEntryLeft{#1}{#2}}

\begin{document} % ====================================

\begin{multicols}{2}[\dotfill\textbf{Contents}\dotfill]

\myTocEntry{Preface}{i}
\myTocEntry{Introduction}{30}
\myTocEntry{Exciting discovery}{5}
\myTocEntry{Visiting Delphi}{10}

\columnbreak % new column =============================
\renewcommand{\myTocEntry}[2]{%
  \myTocEntryRight{#1}{#2}}

\myTocEntry{First-order problems}{20}
\myTocEntry{The pit}{30}
\myTocEntry{Not all is lost}{35}
\myTocEntry{Breakthrough}{42}

\end{multicols}

\end{document} % ======================================
3
  • 1
    Possible duplicate: Detecting current column in multicol
    – Werner
    Mar 8, 2018 at 16:25
  • Will you always create the ToC manually?
    – Werner
    Mar 8, 2018 at 16:28
  • @Werner no, I would like it done automatically. Your link looks perfect. Reading it now.
    – Tássio
    Mar 8, 2018 at 16:38

1 Answer 1

1

It is really part of multicol packages for quite some time: option colactionand comand \docolaction.

0

You must log in to answer this question.

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