%20dentro%20de%20um%20ambiente.png)
Dentro de um ambiente (veja Recursos environ
), coloquei um marginnote
ao lado do cabeçalho do ambiente. O cabeçalho contém algum texto. Se esse texto se estender até o final da linha (mas até um pouco antes disso, como mostra o MWE), então a nota de margem não será mais colocada próxima ao cabeçalho do ambiente (parece que ocorre uma quebra de linha no marginnote
). Por que? E como posso consertar o ambiente para evitar isso? Acho que há um espaço adicional (onde?) gerado a partir do cabeçalho do ambiente que empurra a nota de margem para a próxima linha.
\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}
Responder1
\marginnote
adiciona uma caixa invisível, algo como \mbox{}
. A separação ( \labelsep
) após a \item
adição com os \mbox{}
resultados na linha vazia. BTW: Sem esta caixa você \\
resultaria em umLaTeX Error: There's no line here to end.
Portanto, para evitar o problema, defina \labelsep
como 0pt e (opcionalmente) adicione \\
à definição do ambiente.
\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}
Eu usei \\*
em vez de \\
para evitar quebras de página imediatamente após ocabeçalho.