marginnote 在環境中放置錯誤(換行)

marginnote 在環境中放置錯誤(換行)

在一個環境中(請參閱參考資料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}

在此輸入影像描述

我已經使用\\*而不是\\避免在之後立即分頁標題

相關內容