在环境中(参见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}
我使用过\\*
,以\\
避免在标题。