0

I'm typesetting a tabularx in which some of the cells in one column (of type X) contain itemize lists. I don't like the excessive space above & below the lists (or even between the list items), so I'm using the trick from this answer to eliminate the upper vertical space and this answer to eliminate the lower (Trying to use the latter answer's advice for eliminating the upper vertical space didn't work). Specifically, I've defined this command in the preamble:

\makeatletter
\newcommand{\compress}{\@minipagetrue}
\makeatother

and I've inserted >{\compress} before the X in the column specification.

On its own, this works fine, except that (a) the last row of the table contains regular text, not a list, and (b) the table is immediately followed by a \section. These two facts together result in an output in which there is noticeably too little space between the table and the section header. If I remove the last row of the table, leaving a row with a list as the new last row, or if I delete the \section command, or if I remove the >{\compress}, the spacing goes back to normal, but the first two aren't what I want to typeset, and the last results in the top lines of the rows not lining up.

Minimalish working example:

\documentclass{article}
\usepackage{tabularx}
\makeatletter
\newcommand{\compress}{\@minipagetrue}
\makeatother
\usepackage{enumitem}
\setlist[itemize]{
    itemsep=0.15\baselineskip,
    parsep=0pt,
    % Trick from answer 126505; did not work:
    %before=\vspace*{\dimexpr-\baselineskip-\parskip},
    after=\vspace*{-\baselineskip}
}
\begin{document}

\noindent \begin{tabularx}{\linewidth}{l>{\compress}X} \textbf{Colors} & \begin{itemize} \item Red \item Green \item Blue \end{itemize} \ \textbf{Gems} & \begin{itemize} \item Ruby \item Sapphire \item Emerald \end{itemize} \ \textbf{Elements} & \begin{itemize} \item Fire \item Water \item Earth \end{itemize} \ \textbf{Foo} & Bar \ \end{tabularx}

\section{Next Section} Lorem ipsum\ldots

\end{document}

Result:

jwodder
  • 431

1 Answers1

1

enter image description here

\documentclass{article}
\usepackage{tabularx}
\makeatletter
\newcommand{\compress}{\@minipagetrue}
\newcommand\ifyoudothatyoudbetterdothis{\@minipagefalse}
\makeatother
\usepackage{enumitem}
\setlist[itemize]{
    itemsep=0.15\baselineskip,
    parsep=0pt,
    % Trick from answer 126505; did not work:
    %before=\vspace*{\dimexpr-\baselineskip-\parskip},
    after=\vspace*{-\baselineskip}
}
\begin{document}

\noindent \begin{tabularx}{\linewidth}{l>{\compress}X<{\ifyoudothatyoudbetterdothis}} \textbf{Colors} & \begin{itemize} \item Red \item Green \item Blue \end{itemize} \ \textbf{Gems} & \begin{itemize} \item Ruby \item Sapphire \item Emerald \end{itemize} \ \textbf{Elements} & \begin{itemize} \item Fire \item Water \item Earth \end{itemize} \ \textbf{Foo} & Bar \ \end{tabularx}

\section{Next Section} Lorem ipsum\ldots

\end{document}

@minipage is a global flag. If you set it true you need to ensure that it is set to false, otherwise you will affect some arbitrary unexpected part of the document, such as forcing a following section heading to act as if it is at the top of a page and not add vertical space.

If you have a list in the cell the list code will arrange to set the flag false but with just a bare paragraph you are leaving it true.

Safer than using \@minipagetrue directly would be to do as minipage does and use \@setminipage which is defined as

\def \@setminipage{%
  \@minipagetrue
  \everypar{\@minipagefalse\everypar{}}%
}

Then even your bare paragraph would set it false however you still need to set it false at the end (as \endminipage does) in case the cell is empty or just has a rule or in some other way avoids having a paragraph that triggers \everypar.

David Carlisle
  • 757,742