3

Another update: when applying John Kormylo's answer to karlkoeller's answer from Making marginnote to appear either side of twocolumn, twoside document, make sure that \marginnote is followed by %, and that the \strut is inserted before \begingroup (instead of directly before \oldmarginnote). Otherwise, you will get this:

\documentclass[twocolumn,twoside]{article}
\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%
        \strut%
        \oldmarginnote{#1}%
    \endgroup%
}
\makeatother
\begin{document}
    \lipsum[1-10]
    \section{Section}
    \marginnote{Note}%
    This text usually stays together, but is split across two columns with \verb|\marginnote|.
\end{document}

instead of this:

\documentclass[twocolumn,twoside]{article}
\usepackage{lipsum}
\usepackage{marginnote}
\makeatletter
\let\oldmarginnote\marginnote
\renewcommand*{\marginnote}[1]{%
    \strut%
    \begingroup%
        \ifodd\value{page}%
            \if@firstcolumn\reversemarginpar\fi%
        \else%
            \if@firstcolumn\else\reversemarginpar\fi%
        \fi%
        \oldmarginnote{#1}%
    \endgroup%
}
\makeatother
\begin{document}
    \lipsum[1-10]
    \section{Section}
    \marginnote{Note}%
    This text stays together regardless of \verb|\marginnote|.
\end{document}

Update: This is a much more concise MWE:

\documentclass{article}
\usepackage{lipsum}
\usepackage{marginnote}
\begin{document}
    \lipsum[2-6]
    \section{Section}
    \marginnote{Note}
    This text should follow the section heading without a page break in between! Uncommenting \verb|\marginnote{Note}| fixes things.
\end{document}

So the problem I am facing has nothing to do with needspace or a two-column article. The question remains the same, though: "How can I prevent the page break between the section heading and the following text?"

Based on the accepted answer by @karlkoeller in Making marginnote to appear either side of twocolumn, twoside document, I came up with this MWE:

\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}
    \twocolumn
    \lipsum[2-10]
    \section{Section}
    \marginnote{Note}
    I am OK with the placement of the note, but I would like this text to follow the section heading without a page break in between! Note that uncommenting the \verb|\marginnote{Note}| fixes things.
\end{document} 

How can I prevent the page break between the section heading and the following text?

1
  • \section[Section]{Section\marginnote{\normalfont\normalsize note}}
    – egreg
    Commented May 28, 2015 at 9:45

1 Answer 1

3

This moves the entire section to page 2.

\documentclass{article}
\usepackage{lipsum}
\usepackage{marginnote}
\begin{document}
    \lipsum[2-6]
    \section{Section}
    \strut\marginnote{Note}%
    This text should follow the section heading without a page break in between! Uncommenting \verb|\marginnote{Note}| fixes things.
    \end{document}

This moves the note and text to page 2 and leaves the section title on page 1.

\documentclass{article}
\usepackage{lipsum}
\usepackage{marginnote}
\begin{document}
    \lipsum[2-6]
    \section{Section}
    \null\marginnote{Note}%
    This text should follow the section heading without a page break in between! Uncommenting \verb|\marginnote{Note}| fixes things.
    \end{document}
1
  • 1
    Thanks. Important to note: the % after \marginnote{Note}!
    – bers
    Commented May 28, 2015 at 12:35

You must log in to answer this question.

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