10

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.

  • Does it have to happen automatically, or is specifying the margin as an argument an option? – Steven B. Segletes Feb 6 '15 at 11:58
  • 1
    @StevenB.Segletes It should happen automatically. – Jagath Feb 6 '15 at 12:24
8

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

  • 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 6 '15 at 14:29
  • @JagathAR What do you mean? – karlkoeller Feb 6 '15 at 17:06
  • I am sorry. Please read it as "beginning of a page". Sorry for the confusion. – Jagath Feb 9 '15 at 4:42
  • @JagathAR Oh, I see. See the edit. – karlkoeller Feb 9 '15 at 6:27
  • 1
    Since there is no comment on the importance of \begingroup (w.r.t. to \reversemarginpar), tex.stackexchange.com/questions/98126 may be relevant for anyone adapting this example. Apart from that, excellent answer. – bers May 4 '15 at 22:46

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.