# Vertical alignment of lrbox with minipage inside

I'm trying to make an environment that prints highlighted notes, and I can't get the vertical alignment right. Here's a minimal example:

\documentclass{article}

\usepackage{xcolor}
\usepackage{calc}

\makeatletter%
\newenvironment{note}{%
\begin{lrbox}{\@tempboxa}\begin{minipage}[t]{\linewidth-7pt}%
\setlength{\parskip}{8pt}%
\textbf{Note.}}%
{\end{minipage}\end{lrbox}%
}%
\makeatother%

\begin{document}

\begin{enumerate}
\item
\begin{note}
This alignment is what I want.

The top lines up with the number.
\end{note}

\item
\begin{note}
But if there's a list in the note, the number instead matches up
with the first item.

\begin{itemize}
\item A
\item B
\end{itemize}
\end{note}
\end{enumerate}

\end{document}


This produces the following:

I'd like the highlighted box to be top-aligned with the enumerate numbers to the left; the first one is fine, but the second one is using the first item of the itemize instead. What have I done wrong?

Subtle problem. You see that not only the box is displaced, but also the item number.

One should never say \item \colorbox{color}{text}, but always

\item \leavevmode\colorbox{color}{text}


because of funny interactions of color setting and \item.

\documentclass{article}

\usepackage{xcolor}
\usepackage{calc}

\newsavebox{\notebox}
\newenvironment{note}
{\leavevmode
\begin{lrbox}{\notebox}
\begin{minipage}[t]{\linewidth-2\fboxsep}%
\setlength{\parskip}{8pt}%
\textbf{Note.} \ignorespaces}
{\end{minipage}
\end{lrbox}%
}

\begin{document}

\begin{enumerate}
\item
\begin{note}
This alignment is what I want.

The top lines up with the number.
\end{note}

\item
\begin{note}
But if there's a list in the note, the number instead matches up
with the first item.

\begin{itemize}
\item A
\item B
\end{itemize}
\end{note}

\end{enumerate}

\end{document}


I'd avoid using \@tempboxa, preferring a new box register. I made also a couple of adjustments. I'd also avoid setting \parskip.

Basically, what happens is that processing \item is unfinished and the inner \item takes over.