# Spacing after itemize (without parskip package)

This piece of code seemed to be working fine for a long time, until I try to remove the parskip package. Without this package, it seems that I need to include two hacks:

1. Add a \vspace{-\baselineskip} before and after the itemize environment.
2. Need a \strut to be added.

So without parskip, and with these two hacks I obtain the desired results:

But without the hacks, which is obtained by ensuring the following are un-commented:

\renewcommand{\HackVSpace}{}%
\renewcommand{\HackStrut}{}%


this yields:

Surely there is a less hackish solution to this. And, what is special about parskip that I was getting the desired behavior.

## Notes:

• In actual usage I am only really using this for a single item and itemize provides the desired formatting, so I could do without itemize. But am still interested to know how to control itemize.

## Code:

%\def\UseParskipPackage{}% Need to work with this commented.

\documentclass{article}
\usepackage{xcolor}
\usepackage{enumitem}
\usepackage{showframe}

\ifdefined\UseParskipPackage
\usepackage{parskip}
\newcommand{\HackVSpace}{}%
\newcommand{\HackStrut}{}%
\else
\newcommand{\HackVSpace}{\vspace{-\baselineskip}}%
\newcommand{\HackStrut}{\strut}%
\fi

%% Remove the hack - comment these out and things work fine
%% with or without the parskip package
\renewcommand{\HackVSpace}{}%
\renewcommand{\HackStrut}{}%

\begin{document}

\noindent
\colorbox{blue!20}{%
\parbox[t]{\dimexpr\linewidth-2\fboxsep\relax}{%
\HackVSpace%
\begin{itemize}[label={\small \texttt{X:}}]%
\item \HackStrut\texttt{some text fff yyy}%
\end{itemize}%
\HackVSpace%
}}%
%
\newline
\colorbox{blue!20}{%
\parbox[t]{\dimexpr\linewidth-2\fboxsep\relax}{%
\HackVSpace%
\begin{itemize}[label={\small \texttt{Y:}}]%
\item \HackStrut\texttt{some more text fff yyy}%
\end{itemize}%
\HackVSpace%
}%
}%
\end{document}

-
Would adding the nosep option to itemize help? –  egreg Jun 10 '13 at 22:18
@egreg: Well, it seems to do a lot more than help -- it seems to fix the problem completely!!! :-) Thanks. Testing in actual use case now... –  Peter Grill Jun 10 '13 at 22:27

The parskip package changes the definition of \@listi, \@listii and \@listiii to use different values for the parameters \topsep, \itemsep and \parsep; it sets the first two to zero and the third to \parskip.

This explains why you don't get additional space in the box when parskip is loaded. When it isn't, the normal spacings are applied.

Solution, independent on parskip: add nosep to the options passed to itemize.

\documentclass{article}
\usepackage{xcolor}
\usepackage{enumitem}
\usepackage{showframe}

\begin{document}

\noindent
\colorbox{blue!20}{%
\parbox[t]{\dimexpr\linewidth-2\fboxsep\relax}{
\begin{itemize}[label={\small \texttt{X:}},nosep]
\item \texttt{some text fff yyy}
\end{itemize}
}%
}
\newline
\colorbox{blue!20}{%
\parbox[t]{\dimexpr\linewidth-2\fboxsep\relax}{
\begin{itemize}[label={\small \texttt{Y:}},nosep]
\item \texttt{some more text fff yyy}
\end{itemize}
}%
}
\end{document}


-

space is discarded at the top of pages, but not at the top of boxes. LaTeX emulates this behaviour, which is the main difference between minipage and \parbox

%\def\UseParskipPackage{}% Need to work with this commented.

\documentclass{article}
\usepackage{xcolor}
\usepackage{enumitem}
\usepackage{showframe}

\ifdefined\UseParskipPackage
\usepackage{parskip}
\newcommand{\HackVSpace}{}%
\newcommand{\HackStrut}{}%
\else
\newcommand{\HackVSpace}{\vspace{-\baselineskip}}%
\newcommand{\HackStrut}{\strut}%
\fi

%% Remove the hack - comment these out and things work fine
%% with or without the parskip package
\renewcommand{\HackVSpace}{}%
\renewcommand{\HackStrut}{}%

\begin{document}

\noindent
\colorbox{blue!20}{%
\parbox[t]{\dimexpr\linewidth-2\fboxsep\relax}{%
\HackVSpace%
\begin{itemize}[label={\small \texttt{X:}}]%
\item \HackStrut\texttt{some text fff yyy}%
\end{itemize}%
\HackVSpace%
}}%
%
\newline
\colorbox{blue!20}{%
\parbox[t]{\dimexpr\linewidth-2\fboxsep\relax}{%
\HackVSpace%
\begin{itemize}[label={\small \texttt{Y:}}]%
\item \HackStrut\texttt{some more text fff yyy}%
\end{itemize}%
\HackVSpace%
}%
}%

\bigskip

\noindent
\colorbox{blue!20}{%
\begin{minipage}[t]{\dimexpr\linewidth-2\fboxsep\relax}%
\HackVSpace%
\begin{itemize}[label={\small \texttt{X:}}]%
\item \HackStrut\texttt{some text fff yyy}%
\end{itemize}%
\HackVSpace%
\end{minipage}}%
%
\newline
\colorbox{blue!20}{%
\begin{minipage}[t]{\dimexpr\linewidth-2\fboxsep\relax}%
\HackVSpace%
\begin{itemize}[label={\small \texttt{Y:}}]%
\item \HackStrut\texttt{some more text fff yyy}%
\end{itemize}%
\HackVSpace%
\end{minipage}%
}%

\end{document}

-