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} % ======================================
Tássio
  • 544

1 Answers1

1

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