環境内で余白の注釈が間違って配置されています(改行)。

環境内で余白の注釈が間違って配置されています(改行)。

環境内 (を参照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.

したがって、この問題を回避するには、 を\labelsep0pt に設定し、(オプションで) を\\環境の定義に追加します。

\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}

ここに画像の説明を入力してください

直後に改ページを避けるために、\\*の代わりにを使用しました。\\見出し

関連情報