Single-spaced multi-line marginalia
You could use \setstretch
and \parbox
inside \colorbox
. Here's an example, using even smaller stretch value to make the effect more visible:
\documentclass{article}
\usepackage[english]{babel}
\usepackage{blindtext}
\usepackage[svgnames]{xcolor}
\usepackage[doublespacing]{setspace}
\newcommand{\mymarginnote}[1]{%
\marginpar{\colorbox{yellow}{\parbox{\marginparwidth}{%
\setstretch{0.5}\textcolor{red}{\scriptsize{#1}}}}}}
\begin{document}
\blindtext
\mymarginnote{Some text in the margin spanning several lines}
\blindtext
\end{document}
The output looks like:
I think the real problem is this.
Wrong spacing:
\newcommand{\mymarginnote}[1]{\marginpar{\textcolor{red}{\scriptsize #1}}}
Right spacing:
\newcommand{\mymarginnote}[1]{\marginpar{\scriptsize\textcolor{red}{#1}}}
Explanation: In the second version, \scriptsize
is still in effect when the paragraph ends. This is the point at which Latex chooses the line spacing for the paragraph.
No need to use any extra tweaks like the "spacing" environment.