24

Is there a way to align a marginpar with the beginning of a paragraph, without cluttering the text of the paragraph?

If I do the following, the marginpar lines up with the last line of the first paragraph.

\documentclass[12pt]{article}
\begin{document}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur scelerisque purus vitae nisl lacinia at volutpat sapien bibendum. Sed mollis ultricies arcu non posuere.
\par
\marginpar{Praesent nulla arcu.}Proin neque ante, placerat in laoreet quis, egestas sit amet leo. Mauris vestibulum cursus elit et vulputate. Cras congue nulla vitae tortor mattis porttitor.
\end{document}

Moving the marginpar after the first word of the second paragraph produces the desired effect, but clutters the source document (especially with longer marginpars). Is there a way to achieve both?

4
  • \hspace{0pt}\marginpar{...} at the front of the paragraph should do the job
    – daleif
    Apr 19, 2011 at 10:07
  • Indeed. Thank you. If you answer again (not in comment) I can assign it "correct answer". In the meanwhile I answer it myself to save other people time.
    – B3ret
    Apr 19, 2011 at 10:18
  • Ok, seems I can not answer my question within 24 hours and I can not close the question either...
    – B3ret
    Apr 19, 2011 at 10:20
  • the delay is to get multiple opinions. In some cases the best answer is not always the first answer that works. Apr 19, 2011 at 11:56

1 Answer 1

22

\leavevmode\marginpar{...} at the front of the paragraph should do the job1.

Minimal example

\documentclass{scrartcl}

\usepackage{kantlipsum}

\begin{document}

\leavevmode\marginpar{Aligned marginline}
\kant[1]

\end{document}

enter image description here

1: See Function and usage of \leavevmode for more information about \leavevmode.

4
  • 16
    Why not \leavevmode instead of `\hspace{0pt}?
    – egreg
    May 23, 2011 at 16:03
  • @egreg, I got the advise from someone else. Is there any particular difference?
    – daleif
    Oct 30, 2014 at 17:49
  • 5
    \leavevmode leaves no trace of itself if already inside a paragraph, while \hspace{0pt} does.
    – egreg
    Oct 30, 2014 at 17:55
  • 1
    It might also be useful after \marginpar to append \ignorespaces to clear justified space between words.
    – user619271
    Jul 29, 2018 at 19:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .