3

I am using marginal note package in two column layout. The below mentioned command does not trigger the two column left and right side.

\ifodd\value{page}
\if@firstcolumn\reversemarginpar\else\normalmarginpar\fi
\else
\if@firstcolumn\reversemarginpar\else\normalmarginpar\fi
\fi

This if then else condition does not working for me.

MWE

    \documentclass[twocolumn]{article}

\usepackage{multicol}
\usepackage{lipsum}
\usepackage{marginnote}

\makeatletter
\let\oldmarginnote\marginnote
\renewcommand*{\marginnote}[1]{%
   \begingroup%
   \ifodd\value{page}
     \if@firstcolumn\reversemarginpar\fi
   \else
     \if@firstcolumn\else\reversemarginpar\fi
   \fi
   \oldmarginnote{#1}%
   \endgroup%
}
\makeatother

\begin{document}

\lipsum[1]\marginnote{Odd page left side note}[-50pt]

\lipsum[2]
\lipsum[3]
\lipsum[4]\marginnote{Odd page right side note}[-50pt]
\lipsum[5]
\lipsum[6]
\lipsum[7]\marginnote{even page left side note}
\lipsum[8]
\lipsum[9]
\lipsum[10]
\lipsum[11]
\lipsum[12]
\lipsum[13]
\lipsum[14]\marginnote{even page right side note}
\lipsum[15]
\lipsum[16]
\lipsum[17]

\clearpage

\onecolumn



\begin{multicols}{2}

\section{Multicol environment begins}

\lipsum[10]\marginnote{Multicol left side note}
\lipsum[11]
\lipsum[12]
\lipsum[13]
\lipsum[14]
\lipsum[15]
\lipsum[16]\marginnote{Multicol right side note}
\lipsum[17]

\end{multicols}


\end{document}

Currently i am using manually given \reversemarginpar and \normalmarginpar. My requirement is auto trigger is working if then else condition. Kindly advice.

2
  • 1
    See tex.stackexchange.com/q/226847/31910
    – Sterry
    Feb 26, 2015 at 13:13
  • @sterry i edit and save my question. I am using vertical shift concept in marginal note. In such cases multicol environment is also i am using. In this two cases the auto triggering macro does not working for me. Kindly advice
    – CS Kumar
    Feb 26, 2015 at 14:52

2 Answers 2

6

The multicol package has a colaction option. You can then do column-dependent actions with the \docolaction command. The three arguments are the actions for the first, middle, and last columns.

This is a simple version but it doesn't handle the optional argument to marginnote (which comes after the mandatory argument, not before it).

    \documentclass{article}

    \usepackage[colaction]{multicol}
    \usepackage{lipsum}
    \usepackage{marginnote}

    \let\oldmarginnote\marginnote
    \renewcommand{\marginnote}[1]
         {\begingroup\docolaction{\reversemarginpar}{}{}\oldmarginnote{#1}\endgroup}

    \begin{document}

    \begin{multicols}{2}
    \section{Multicol environment begins}
    \lipsum[10]\marginnote{lipsum 10}
    \lipsum[11]\marginnote{lipsum 11}
    \lipsum[12]\marginnote{lipsum 12}
    \lipsum[13]\marginnote{lipsum 13}
    \lipsum[14]\marginnote{lipsum 14}
    \lipsum[15]\marginnote{lipsum 15}
    \lipsum[16]\marginnote{lipsum 16}
    \lipsum[17]\marginnote{lipsum 17}
    \end{multicols}

\end{document}

To handle the optional argument, we have to dig down inside the package and change the low-level command that actually does the work:

    \documentclass{article}

    \usepackage[colaction]{multicol}
    \usepackage{lipsum}
    \usepackage{marginnote}

    \makeatletter
    \let\old@mn@@@marginnote\@mn@@@marginnote
    \long\def\@mn@@@marginnote[#1]#2[#3]{%
      \begingroup
      \docolaction{\reversemarginpar}{}{}\old@mn@@@marginnote[{#1}]{#2}[{#3}]%
      \endgroup}
    \makeatother

    \begin{document}

    \begin{multicols}{2}
    \section{Multicol environment begins}
    \lipsum[10]\marginnote{lipsum 10}[-30pt]
    \lipsum[11]\marginnote{lipsum 11}
    \lipsum[12]\marginnote{lipsum 12}
    \lipsum[13]\marginnote{lipsum 13}[-30pt]
    \lipsum[14]\marginnote{lipsum 14}
    \lipsum[15]\marginnote{lipsum 15}[-30pt]
    \lipsum[16]\marginnote{lipsum 16}[-30pt]
    \lipsum[17]\marginnote{lipsum 17}
    \end{multicols}

\end{document}
8
  • I can't run the MWE. The error "! LaTeX Error: Unknown option colaction' for package multicol'." show for me. Second thing is I am using vertical alignment is using like "\marginnote{margin text here}[vshift]". In this case the above macro does not support for me. The optional argument "[-23pt]" show in output. I need marginal note auto triggering macro is working normal "twocolumn" environment and also support "multicol" environment. This logic is working if i using "vshift" alignment marginnotes. Kindly advice.
    – CS Kumar
    Feb 28, 2015 at 6:56
  • docolaction was added in version 1.8 of multicols (user guide is dated November 2014). Maybe you need to update your version of LaTeX. To use vshift, you could add an optional argument to the macro. To use these notes both inside and outside of the multicols enviromment, I would make two different macros. It's hard to make a 100% reliable test of whether you are inside an environment or not.
    – alephzero
    Mar 1, 2015 at 6:19
  • I updated the answer to handle the vshift optional argument.
    – alephzero
    Mar 1, 2015 at 22:30
  • thanks for your solution. Sorry for the late reply. My current system version is "2011/06/27 v1.7a". I will try to update multicol 1.8 version through the "MikTeX Package Manager (Admin)". I will greb "multicol*" the system will show the "tools, polish-doc, bidi,....". I confused and i don't know how to update the 1.8 version multicol package in my system. Kindly advice.
    – CS Kumar
    Mar 5, 2015 at 7:33
  • Sorry, I use TexLive not MikTeX. Actually, I stopped using MixTeX a few years ago because of some problems with (lack of) support - it seemed to be a one-man show.
    – alephzero
    Mar 7, 2015 at 1:35
2

alephzero's answer generally works well (after installing the latest version of multicol), but there was a major problem in my case: with a two-sided document it works correctly on odd pages, but on even pages marginnotes tries to automatically reverse the side it uses, resulting in the notes for the right column showing up on the left and vice versa.

This can be corrected with a \checkoddpage, which is built into memoir or can be obtained from the changepage package – you can simply reverse the opposite column's notes on even pages. I am not using the optional argument of marginnote, so I stuck with the first version and used:

\usepackage{marginnote}
\let\oldmarginnote\marginnote
\strictpagecheck
\renewcommand{\marginnote}[1]
  {%
    \checkoddpage%
    \ifoddpage%
      {\begingroup\docolaction{\reversemarginpar}{}{}\oldmarginnote{#1}\endgroup}%
    \else{%
      {\begingroup\docolaction{}{}{\reversemarginpar}\oldmarginnote{#1}\endgroup}}%
    \fi%
  }

Edit: It's important to declare \strictpagecheck, or captions in the first section of a page may end up on the wrong side.

You must log in to answer this question.

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