환경 내에서 여백이 잘못 배치됨(줄바꿈)

환경 내에서 여백이 잘못 배치됨(줄바꿈)

환경( 참조) 내에서 환경 헤더 옆에 가 배치 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}

여기에 이미지 설명을 입력하세요

나는 \\*대신 \\페이지 나누기를 피하기 위해 다음을 사용했습니다.표제.

관련 정보