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?

Colas
  • 6,772
  • 4
  • 46
  • 96
  • 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
  • I'm a bit ashamed... 2017 – Colas Jul 17 '21 at 16:38
  • Any chance you can update your system to a current version of TeXLive or MikTeX? – Mico Jul 17 '21 at 16:48
  • Since I'm maintaining a project with many people involved, having an old distribution might be actually a good thing. – Colas Jul 17 '21 at 16:51
  • Of course, depending how much time you and your coauthors have at hand, making a collective effort to update everyone's TeX distribution might not be a bad idea either. – Mico Jul 17 '21 at 17:28

1 Answers1

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.

egreg
  • 1,121,712