0

The following picture (MWE follows below) demonstrates the problem. There is a space at the beginning of the list when it begins with a \marginpar. I appreciate that something must be on the line directly after the \item so I tried \mbox and a zero width \makebox, but this didn't help.

picture of MWE

My original intention was to ask with \reversemarginpar but I noticed the same affect happens with simply \marginpar.

%%%%%%%%%%%% 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}
  • 2
    This is not specific to \marginpar either - it's just they way that TeX works. In 2 and 3, you start the text after \item with an \mbox which is a "thing" - even though it's an invisible thing with zero width. If you follow that by white space, big surprise, - LaTeX actually typesets that white space! On the other hand in 4, \marginpar doesn't typeset anything in the main output (it just puts a box in the margin) so the string of whitespace characters (one before it, one after) is merged into a single space when it is typeset. – alephzero Aug 22 '17 at 18:35
3

enter image description here

i would redefine marginpar and then not care for spaces after its use:

\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}
3

You can get lost of that space, by leaving out that space after the argument of \marginnote (\marginnote{margin stuff}Other text). So your MWE should look like:

\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

  • 1
    IMO this is a better answer. Redefining \makepar is trying to make TeX work a different way from how Knuth designed it. Even if you succeed for one command, there will be another, and another, and another - and then your redefinitions might start interacting with each other ... ! Much better just to learn how to use it the way it was intended to be used, and don't put a space in the input where you don't want one in the output. – alephzero Aug 22 '17 at 18:40
  • @alephzero totally agreed. Learning how to use correct syntax is the preferable way here, because the same issue could arise from almost every macro taking one or more arguments... – Skillmon Aug 22 '17 at 19:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.