由于以 \marginpar 开头,如何删除项目中的空格?

由于以 \marginpar 开头,如何删除项目中的空格?

下图(MWE 如下所示)演示了这个问题。当列表以 \marginpar 开头时,列表开头有一个空格。我知道 \item 后面的行上一定有内容,所以我尝试了 \mbox 和零宽度 \makebox,但这没有帮助。

picture of MWE

我原本的意图是用 \reversemarginpar 来询问,但我注意到仅使用 \marginpar 也会出现同样的效果。

%%%%%%%%%%%%% 中压 %%%%%%%%%%%%%%%%%%%%%%%

\documentclass{article}

\usepackage{marginnote}

\begin{document}
\begin{enumerate}

\item Some text to see what happens when we get to a second line and if there is a space at the fron or not.

\item \mbox{}\marginpar{(A space)} Some text to see what happens when we get to a second line and if there is a space at the fron or not.

\item \makebox[0pt][l]{}\marginpar{(A space)} Some text to see what happens when we get to a second line and if there is a space at the fron or not.

\item Some text \marginpar{(OK, but not nice code)} to see what happens when we get to a second line and if there is a space at the fron or not.

\end{enumerate}
\end{document}

答案1

enter image description here

我会重新定义marginpar然后在使用后不再关心空格:

\documentclass{article}

%\usepackage{marginnote} % not needed
\let\oldmarginpar\marginpar
    \renewcommand{\marginpar}[1]{%
        \leavevmode%
        \oldmarginpar{#1}%
        \ignorespacesafterend\ignorespaces%
                              }

\begin{document}
\begin{enumerate}

\item Some text to see what happens when we get to a second line and if there is a space at the front or not.

\item \marginpar{(A space)}Some text to see what happens when we get to a second line and if there is a space at the front or not.

\item \marginpar{(A space)} Some text to see what happens when we get to a second line and if there is a space at the front or not.

\item \marginpar{(OK, but not nice code)}    to see what happens when we get to a second line and if there is a space at the front or not.

\end{enumerate}
\end{document}

答案2

\marginnote通过在( )参数后面省略该空格,您可以丢失该空格\marginnote{margin stuff}Other text。因此,您的 MWE 应如下所示:

\documentclass{article}

\usepackage{marginnote}

\begin{document}
\begin{enumerate}

\item Some text to see what happens when we get to a second line and if there is a space at the fron or not.

\item \mbox{}\marginpar{(A space)}Some text to see what happens when we get to a second line and if there is a space at the fron or not.

\item \makebox[0pt][l]{}\marginpar{(A space)}Some text to see what happens when we get to a second line and if there is a space at the fron or not.

\item Some text \marginpar{(OK, but not nice code)}to see what happens when we get to a second line and if there is a space at the fron or not.

\end{enumerate}
\end{document}

enter image description here

相关内容