0

In the following MWE,

\documentclass{article}

\usepackage{multicol}
\usepackage{hyperref}

\newcounter{counterForCalcul}
\setcounter{counterForCalcul}{0}
\def\incrementCounterForCalcul{\refstepcounter{counterForCalcul}}

\begin{document}

\begin{multicols}{2}
\incrementCounterForCalcul Test

\incrementCounterForCalcul Test

\incrementCounterForCalcul Test

\incrementCounterForCalcul Test

\incrementCounterForCalcul Test

\incrementCounterForCalcul Test

\incrementCounterForCalcul Test

\incrementCounterForCalcul Test
\end{multicols}

\end{document}

there should be two columns but there is only one.

How can I overcome this issue?

9
  • 1
    I am unable to reproduce the issue you say you're experiencing, i.e., I get two columns with four lines each, not just one column. My system runs MacTeX2021 (all updates installed), LaTeX2e <2021-06-01> patch level 1, L3 programming layer <2021-07-12>, multicol 2019/12/09 v1.8, and hyperref 2021-06-07 v7.00m. Please tell us more about your computing setup.
    – Mico
    Jul 17 '21 at 15:05
  • Thanks. Interesting, my distribution is older... I solved the issue by replacing \ refstepcounter by \stepcounter
    – Colas
    Jul 17 '21 at 15:16
  • Just curious: how old is your TeX distribution? Incidentally, if you plan on creating cross-references to the items, you'll be unpleasantly surprised if you're using stepcounter.
    – Mico
    Jul 17 '21 at 15:25
  • What is the command to know how old it is?
    – Colas
    Jul 17 '21 at 15:49
  • You need to look at the first few lines of the log file. If your tex file is called main.tex, the log file will be called main.log.
    – Mico
    Jul 17 '21 at 16:25
0

This doesn't happen with TeX Live 2020 (or later), multicol version 1.8y and hyperref version v7.00k.

It happens with TeX Live 2019 with hyperref version 7.00d.

You can work around the issue by emitting \leavevmode before \refstepcounter, which I'd recommend anyway, because it will produce the anchor in the expected place.

\documentclass{article}

\usepackage{multicol}
\usepackage{hyperref}

\newcounter{counterForCalcul}
\setcounter{counterForCalcul}{0}
\newcommand\incrementCounterForCalcul{%
  \leavevmode
  \refstepcounter{counterForCalcul}%
}

\begin{document}

\begin{multicols}{2}
\incrementCounterForCalcul Test

\incrementCounterForCalcul Test

\incrementCounterForCalcul Test

\incrementCounterForCalcul Test

\incrementCounterForCalcul Test

\incrementCounterForCalcul Test

\incrementCounterForCalcul Test

\incrementCounterForCalcul Test
\end{multicols}

\end{document}

enter image description here

I generated the picture by running TeX Live 2012, so it should be safe with all later releases.

Avoid \def in documents, unless you have specific reasons to use it. See Fun: How can we generate funny/unexpected messages in LaTeX? for a funny example.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.