另一个更新:将 John Kormylo 的回答应用于 karlkoeller 的回答时使边注出现在两栏、双面文档的两侧,确保 后面\marginnote
跟着%
,并且\strut
插入在 之前\begingroup
(而不是直接在 之前\oldmarginnote
)。否则,您将得到以下结果:
\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}
而不是这样:
\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}
更新:这是一个更加简洁的 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}
所以我面临的问题与双栏文章无关needspace
。但问题仍然相同:“如何防止章节标题和以下文本之间出现分页符?”
根据@karlkoeller 接受的答案使边注出现在两栏、双面文档的两侧,我想出了这个 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}
如何防止章节标题和后续文本之间出现分页符?
答案1
这会将整个部分移至第 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}
这会将注释和文本移至第 2 页,并将章节标题保留在第 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}