11

I have the following MWE in which the \marginnote need to appear at correct margin. For example the margin notes one, two, three and four need to appear on left margin of first page. In the second page the margin notes thirteen and fourteen should appear on right side.

The command \reversemarginpar corrects this, but I need to reset on next column. I am not able to use the twocolumn document class option as I am using \twocolumn[] to set the title part of the document.

I will not be able to use other class files. Is there an easy way to put the margin notes to the respective margins.


MWE

\documentclass[twoside]{article}

\RequirePackage{lipsum}
\RequirePackage[margin=2cm]{geometry}
\RequirePackage{marginnote}

\begin{document}
\sloppy

\twocolumn[{%
\hrulefill\medskip\par
\lipsum[1]
\hrulefill
\vspace*{2pc}
}]


\section{Two}\label{s2}
\marginnote{One}\lipsum[1]
\marginnote{Two}\lipsum[2] 
\marginnote{Three}\lipsum[3]
\marginnote{Four}\lipsum[4]
\marginnote{Five}\lipsum[5]
\marginnote{Six}\lipsum[6]
\marginnote{Seven}\lipsum[7]

\section{Three}\label{s3}
\marginnote{Eight}\lipsum[1]
\marginnote{Nine}\lipsum[2] 
\marginnote{Ten}\lipsum[3]
\marginnote{Eleven}\lipsum[4]
\marginnote{Twelve}\lipsum[5]
\marginnote{Thirteen}\lipsum[6]
\marginnote{Fourteen}\lipsum[7]

\end{document}

There are certain post available here with \marginnote which is not exactly what I am looking for.

Jagath
  • 4,287

1 Answers1

9

Add the following lines in your preamble:

\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

MWE:

\documentclass[twoside]{article}

\usepackage{lipsum}
\usepackage[margin=2cm]{geometry}
\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}

\sloppy

\twocolumn[{%
\hrulefill\medskip\par
\lipsum[1]
\hrulefill
\vspace*{2pc}
}]


\section{Two}\label{s2}
\marginnote{One}\lipsum[1]
\marginnote{Two}\lipsum[2]
\marginnote{Three}\lipsum[3]
\marginnote{Four}\lipsum[4]
\marginnote{Five}\lipsum[5]
\marginnote{Six}\lipsum[6]
\marginnote{Seven}\lipsum[7]


\section{Three}\label{s3}
\marginnote{Eight}\lipsum[1]
\marginnote{Nine}\lipsum[2]
\marginnote{Ten}\lipsum[3]
\marginnote{Eleven}\lipsum[4]
\marginnote{Twelve}\lipsum[5]
\marginnote{Thirteen}\lipsum[6]
\marginnote{Fourteen}\lipsum[7]

\end{document} 

Output:

enter image description here


To avoid having paragraphs at the beginning of a page with an orphan margin note in the previous page, you can load the needspace package and add \needspace{\baselineskip} to the re-definition of \marginnote

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

MWE (try removing \needspace{\baselineskip} to see the difference)

\documentclass[twoside]{article}

\usepackage{lipsum}
\usepackage[margin=2cm]{geometry}
\usepackage{marginnote}
\usepackage{needspace}

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


\begin{document}

\sloppy

\twocolumn[{%
\hrulefill\medskip\par
\lipsum[1]
\hrulefill
\vspace*{2pc}
}]


\section{Two}\label{s2}
\marginnote{One}\lipsum[1]
\marginnote{Two}\lipsum[1]
\marginnote{Three}\lipsum[1]
\marginnote{Four}\lipsum[1]
\marginnote{Five}\lipsum[2]
\marginnote{Six}\lipsum[2]
Some text\par
Some text\par
Some text\par
\marginnote{Seven}\lipsum[1]
\end{document} 

Output

enter image description here

karlkoeller
  • 124,410
  • I have now accepted this as an answer. But is there any way if some marginnote which appear on beginning of a line appear properly. – Jagath Feb 06 '15 at 14:29
  • @JagathAR What do you mean? – karlkoeller Feb 06 '15 at 17:06
  • I am sorry. Please read it as "beginning of a page". Sorry for the confusion. – Jagath Feb 09 '15 at 04:42
  • @JagathAR Oh, I see. See the edit. – karlkoeller Feb 09 '15 at 06:27
  • 1
    Since there is no comment on the importance of \begingroup (w.r.t. to \reversemarginpar), https://tex.stackexchange.com/questions/98126/ may be relevant for anyone adapting this example. Apart from that, excellent answer. – bers May 04 '15 at 22:46
  • 1
    After changing the document class to IEEEtran, the margin note Four moves to the left side. Any idea how to prevent this? – Alex Mar 15 '17 at 23:08