# test which column in multicol

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

\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} % ======================================

• Possible duplicate: Detecting current column in multicol Mar 8 '18 at 16:25
• Will you always create the ToC manually? Mar 8 '18 at 16:28
• @Werner no, I would like it done automatically. Your link looks perfect. Reading it now. Mar 8 '18 at 16:38

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