# How to know which margin a marginnote is on?

Is there a way to make a macro based on \marginnote that varies depending on whether the note is on the right column or the left? In particular I want to do this in two-column mode, otherwise I could check if the page is odd. Below is an mwe, where I want 'left' and 'right' to be decided automatically:

\documentclass[twocolumn]{article}

\usepackage{lipsum}
\usepackage{marginnote}

\begin{document}
\lipsum[1]

\marginnote{left}
\lipsum[2-4]

\marginnote{right}
\lipsum[5]
\end{document}

• One approach would be to adapt this answer to look at the x position instead of the y. – Teepeemm Aug 19 '18 at 2:03

There are two fact to know first:

• marginnote's \marginnote command has an optional argument. If the optional (and the mandatory) argument is used, the optional argument it printed, if marginnote decides to use the left margin, and the the mandatory argument is printed, if marginnote decides to use the right margin.

• In two-column documents marginnote always uses the left margin for notes of the left column and the right margin for notes of the right column.

These two facts result in one more fact:

• If you use the optional (and the mandatory) argument of \marginnote in a two-column document, the optional argument will be used for notes of the left column and the mandatory argument will be used for notes of the right column.

So you can use:

\documentclass[twocolumn]{article}

\usepackage{lipsum}
\usepackage{marginnote}

\begin{document}
\lipsum[1]

\marginnote[L]{R}
\lipsum[2-4]

\marginnote[L]{R}
\lipsum[5]
\end{document}


Specifically for two column mode, one can use \if@firstcolumn.

\documentclass[twocolumn]{article}

\usepackage{lipsum}
\usepackage{marginnote}

\makeatletter
\newcommand{\autoleftright}{\if@firstcolumn left\else right\fi}
\makeatother

\begin{document}
\lipsum[1]

\marginnote{\autoleftright}
\lipsum[2-4]

\marginnote{\autoleftright}
\lipsum[5]
\end{document}

• If a paragraph gets broken across columns, is this able to tell whether the margin note happened before or after the break? – Teepeemm Aug 19 '18 at 2:00
• @Teepeemm No, it's not, unfortunately. – ronno Aug 19 '18 at 2:17