[Tex/LaTex] why does \hspace{0pt} produce a space at the beginning of the paragraph together with \marginpar


Similar situation as in Align marginpar with beginning of paragraph.

Basically I need to align the margin note to the beginning of the paragraph, and I'm putting the \marginpar command before the first word of the paragraph. This can be done by adding a \hspace{0pt} before the \marginpar command.

However, I'm also setting \parindent to 0pt, and this will produce a space at the beginning of the paragraph. Currently I'm using something like \hspace{-0.15cm} as a hack to fixed this problem, but it's not very pretty, any better solutions?

(I have tried the marginnote package, but there are still a few problems. It automatically aligns the margin note to the first line of the paragraph, except when there is a page break and the margin note will appear on the previous page. The longer margin notes will also overlap.)

Best Answer

If you never need the optional argument to \marginpar you can use \initmarginpar defined as


Otherwise always remember to protect the end of line with a comment character:

\marginpar{Margin note}%
Start of the paragraph...

I believe that \leavevmode (or even more \quitvmode) is much better than \hspace{0pt}.

Related Question