0

When a list is the first item in a cell, it has a big vertical space above. In order to remove this space, classical answers are based on inserting \@minipagetrue before the list. Unfortunately, this does not seem sufficient when colors come into play:

\documentclass{article}
\begin{document}
\ExplSyntaxOn
\makeatletter
\begin{center}
\setlength{\tabcolsep}{0mm}
\begin{tabular}{p{0.2\linewidth}p{0.2\linewidth}p{0.2\linewidth}p{0.2\linewidth}p{0.2\linewidth}}
ABCDE
&
\begin{minipage}{\textwidth}
\trivlist
\item
ABCDE
\endtrivlist
\end{minipage}
&
\@minipagetrue
\trivlist
\item
ABCDE
\endtrivlist
&
\begin{minipage}{\textwidth}
\trivlist
\item
\color_select:n{green}
ABCDE
\endtrivlist
\end{minipage}
&
\@minipagetrue
\trivlist
\item
\color_select:n{green}
ABCDE
\endtrivlist
\end{tabular}
\end{center}
\makeatother
\ExplSyntaxOff
\end{document}

With output 5 ABCDE

I would like the green ABCDE on the right to be vertically aligned with the left one, without using a minipage.

0

1 Answer 1

3

Adding \leavevmode before \color_select:n will solve your problem.

\@minipagetrue
\trivlist
\item \leavevmode
\color_select:n{green}
ABCDE
\endtrivlist

enter image description here


But here is a better solution with tabularray package. It provides varwidth library and measure=vbox option for lists, and stretch=-1 option for removing vertical spaces above lists.

\documentclass{article}

\usepackage{tabularray}
\UseTblrLibrary{varwidth}

\usepackage{xcolor}
\usepackage{enumitem}

\begin{document}

\begin{center}
\SetTblrInner[tblr]{measure=vbox,stretch=-1,colsep=0mm}
\setlist[trivlist]{nosep}
\begin{tblr}{colspec={XXXXX},hlines}
ABCDE
&
\begin{trivlist}
\item ABCDE
\end{trivlist}
&
\begin{trivlist}
\item ABCDE
\end{trivlist}
&
\begin{trivlist}
\item \leavevmode\color{green}ABCDE
\end{trivlist}
&
\begin{trivlist}
\item \leavevmode\color{green}ABCDE
\end{trivlist}
\end{tblr}
\end{center}

\end{document}

enter image description here

5
  • Do you know why isn't \leavevmode a part of the \item command ? May 20, 2022 at 13:15
  • @JérômeLAURENS I think that would cause problems in other use cases. But I can not give you an example at present.
    – L.J.R.
    May 20, 2022 at 14:51
  • So this solution is only valid if the \item body is in horizontal mode. Is there a solution without \leavevmode? May 21, 2022 at 5:40
  • @JérômeLAURENS Use \textcolor instead of \color.
    – L.J.R.
    May 21, 2022 at 6:20
  • The argument or \textcolor is in horizontal mode, which is equivalent to using \leavevmode. May 21, 2022 at 6:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .