
環境内 (を参照environ
) で、marginnote
環境ヘッダーの横に を配置しています。ヘッダーにはテキストが含まれています。そのテキストが行末に向かって (ただし、MWE が示すようにその少し前まで) 伸びると、余白メモは環境ヘッダーの横に配置されなくなります ( で改行が発生するようですmarginnote
)。なぜでしょうか。また、これを回避するには、環境をどのように修正すればよいでしょうか。環境ヘッダーから追加のスペース (どこにあるのでしょうか) が生成され、余白メモが次の行に押し出されるのだと思います。
\documentclass{scrbook}
\usepackage[american]{babel}
\usepackage{amsmath}
\usepackage{marginnote}
\usepackage{hyperref}
% Environment
\newcounter{counter}% environment counter
\numberwithin{counter}{chapter}% number counter within chapters
\makeatletter
\newenvironment{environ}[2][]{\refstepcounter{counter}\par
\normalfont\topsep6\p@\@plus6\p@\relax
\trivlist
\item[\hskip\labelsep\sffamily\bfseries MyEnviro~\thecounter\ #1]%
\marginnote{OtherEnviro p.~\pageref{#2}}\ignorespaces
}{%
\endtrivlist\@endpefalse
}
\makeatother
\begin{document}
\chapter{That's the problem}
\begin{environ}[(Some text which covers the amount of space to show the problem)]{foobar}\\
This seems odd (vertical space, wrong placement 'OtherEnviro') because the line
is actually not ending there.
\end{environ}
\begin{environ}[(Some shorter text to show that there's no problem here)]{foobar}\\
This is okay
\end{environ}
\end{document}
答え1
\marginnote
は、 のような目に見えないボックスを追加します\mbox{}
。 の後の区切り ( \labelsep
) は、と空の行に\item
追加されます。 ところで、このボックスがないと、\mbox{}
\\
LaTeX Error: There's no line here to end.
したがって、この問題を回避するには、 を\labelsep
0pt に設定し、(オプションで) を\\
環境の定義に追加します。
\documentclass{scrbook}
\usepackage[american]{babel}
\usepackage{amsmath}
\usepackage{marginnote}
\usepackage{hyperref}
% Environment
\newcounter{counter}% environment counter
\numberwithin{counter}{chapter}% number counter within chapters
\makeatletter
\newenvironment{environ}[2][]{\refstepcounter{counter}\par
\normalfont\topsep6\p@\@plus6\p@\relax
\trivlist
\labelsep 0pt
\item[\hskip\labelsep\sffamily\bfseries MyEnviro~\thecounter\ #1]%
\marginnote{OtherEnviro p.~\pageref{#2}}\\*
\ignorespaces
}{%
\endtrivlist\@endpefalse
}
\makeatother
\begin{document}
\chapter{That's the problem}
\begin{environ}[(Some text which covers the amount of space to show the problem)]{foobar}
This seems odd (vertical space, wrong placement 'OtherEnviro') because the line
is actually not ending there.
\end{environ}
\begin{environ}[(Some shorter text to show that there's no problem here)]{foobar}
This is okay
\end{environ}
\end{document}
直後に改ページを避けるために、\\*
の代わりにを使用しました。\\
見出し。