I am having a small challenge in controlling the vertical spacing in tabularx. As you can see below, the top and bottom padding appear to be more only when using itemize (perhaps with other \begin{} \end{}
also). I have removed all vertical separators in the itemize by using nosep
as can be seen in the sample outside of tabularx below. So my guess is this is something happening within tabularx.
I tried using makecell
, and also \extrarowheight
(as suggested by some other threads), but the vertical spaces remain unchanged.
Would appreciate any help!
\documentclass[12pt,a4paper]{article}
\usepackage{enumitem}
\usepackage{tabularx}
\usepackage{makecell}
\begin{document}
%{\setlength{\extrarowheight}{0pt} % doesn't work
%\setcellgapes{0pt} % doesn't work either
%\makegapedcells % ditto
\begin{tabularx}{\linewidth}{|X|X|}
\hline
Col 1 & Col 2\\
\hline
\multicolumn{2}{|>{\hsize=\dimexpr2\hsize+2\tabcolsep+\arrayrulewidth\relax}X|}{Note the vertical space above and below this cell.}\\
\hline
\multicolumn{2}{|>{\hsize=\dimexpr2\hsize+2\tabcolsep+\arrayrulewidth\relax\linewidth=\hsize}X|}{
\begin{itemize}[nosep,align=left,leftmargin=*]
\item The first item in itemize, note the vertical space above this. A bit more to show.
\item The second item in itemize, note the vertical space below this.
\end{itemize}}\\
\hline
\end{tabularx}
\hrule
\begin{itemize}[nosep,align=left,leftmargin=*]
\item The first item in itemize, note the vertical space above this. A bit more to show.
\item The second item in itemize, note the vertical space below this.
\end{itemize}
\hrule
\end{document}
Best Answer
The
enumitem
package provides the optionsbefore=...
andafter=...
to control what comes before and after the list itself. One can use these options to encase the list in aminipage
; this is useful because, by default, any whitespace padding above and below aminipage
is eliminated automatically.As the example below shows, it's actually preferable to use the
minipage
with the[t]
("top") positinioning specifier, as that will assure that the first line in the first list item will be aligned with lines elsewhere in the table (here: Col0).