Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm trying to use a \marginnote along with a specified \parskip. However, I'm having an alignment issue. With the code in the group with the \parskip the margin note is misaligned with the text on the line, while if I manually put in the gap, then everything works.

Here is a screen shot of a PDF:

Here is a MWE:

\documentclass[10pt, letterpaper]{article} 
\usepackage{geometry} 
\geometry{letterpaper, hmargin=1.5in, vmargin=1in, marginparsep=7pt, marginparwidth=.6in}
\usepackage{marginnote}
\newcommand{\years}[1]{\marginnote{\footnotesize #1}}
\renewcommand*{\raggedleftmarginnote}{}
\setlength{\marginparsep}{7pt}
\setlength\parindent{0pt}
\reversemarginpar
\begin{document}
this doesn't work:\\

\begingroup
\setlength{\parskip}{0.3cm}
\years{2008}blah blah blah\\*
line 2\\*
line 3

\years{2008}blah blah blah\\*
line 2\\*
line 3
\endgroup\\\\
this does:\\

\years{2008}blah blah blah\\*
line 2\\*
line 3\\[0.3cm]
\years{2008}blah blah blah\\*
line 2\\*
line 3
\end{document}
share|improve this question

2 Answers 2

up vote 9 down vote accepted

adding \mbox{} (or \leavevmode) as in:

\newcommand{\years}[1]{\mbox{}\marginnote{\footnotesize #1}}

will fix your alignment (although all the lines ending with \\ look very suspicious (and generate warnings about underfull boxes)

This works because the alignment works best if the float is tied to the paragraph, so if the insert is in the first line rather than before it. It then automatically aligns. If you put the insert in the vertical material before the paragraph you can fix up the vertical spacing but especially if you are changing the vertical spacing mid document, it's harder. \mbox just forces the paragraph to start with an invisible box, so the insert happens within the first line. It would be enough to use \leavevmode (which is used in the definition of \mbox as you do not need the box here, just to force the vertical material to end and the paragraph to start.

share|improve this answer
    
Could you explain what this does or why it's necessary? –  doncherry Feb 19 '12 at 20:34
3  
I don't know the package, but I assume it's basically similar to the standard marginparnote. The alignment works best if the float is tied to the paragraph, so in insert is in the first line rather than before it. Then it automatically aligns. If you put the insert in the vertical material before the paragraph you can fix up the vertical spacing but especially if you are changing the vertical spacing mid document, it's harder. \mbox just forces the paragraph to start with an invisible box, so the insert happens within the first line. –  David Carlisle Feb 19 '12 at 20:40
1  
Thanks! I think you can/should go ahead and edit this into your answer to make it even better. As an explanatory resource for \leavevmode, I found tex.stackexchange.com/questions/22852/…. –  doncherry Feb 19 '12 at 21:45

I won't delete this answer, because of the comments, but I do encourage you to read the other answer, which is considerably better.


I believe this is because you "need to start the paragraph" before starting the marginal. You can do this:

\newcommand{\years}[1]{\hspace{0pt}\marginnote{\footnotesize #1}}
share|improve this answer
    
So I assume \hspace leaves vertical mode as well? –  doncherry Feb 19 '12 at 21:43
1  
yes, or \indent or \leavevmode which does nothing but leave vertical mode and start a para, but \mbox{} is probably the least strange looking construct, although it only works because its definition starts with \leavevmode –  David Carlisle Feb 19 '12 at 21:47
    
@DavidCarlisle: Would it be sensible to delete this answer? –  Brent.Longborough Feb 20 '12 at 1:16
    
@David since when does \indent nothing? if in h-mode it adds a box of width of the indentation which is not a good idea. So it has to be \leavevmodeor anything that calls that internally like \mboxor \hspace but otherwise does no harm. –  Frank Mittelbach Mar 2 '12 at 12:00
    
@FrankMittelbach, er yes, you are right of course, maybe I should just delete the comment, since I can't edit it and it doesn't add much over the answer. –  David Carlisle Mar 2 '12 at 12:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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