1

I want to make a table with a list in a cell.

After some learning, I write code like this.

\documentclass{article}
\usepackage{array}
\usepackage{enumitem}
\begin{document}
    \begin{table}
        \centering
        \setlist[itemize]{noitemsep}
        \begin{tabular}{m{2cm}<{\raggedright}|m{2cm}<{\raggedright}}\hline
            a & \begin{itemize}
                \item B
                \item C
                \item D
            \end{itemize}\\\hline
            e & \begin{itemize}
                \item F
                \item G
                \item H
            \end{itemize}\\\hline
        \end{tabular}
    \end{table}
\end{document}

And it looks like this output.

This table is already good enough. But what makes me unpleasant is the list seem to be not that vertical center, it is kind of leaning towards the top. And there are some spaces wasted. I want to make the list more close to the border. For the first problem, I can use \setlist[itemize]{noitemsep,topsep=xpt} to make the list more center, but that makes more blank. So how can I remove the blank above and below the list and still make other cells' content vertical center?

oneplus
  • 43
  • 5

2 Answers2

1
\documentclass{article}
\usepackage{array}
\usepackage{enumitem}

\newlist{tabular-list}{itemize}{1}
\setlist[tabular-list]
  {
    nosep,     
    topsep     = 2pt ,
    partopsep  = 0pt ,
    leftmargin = 1em ,
    label      = $\bullet$ ,
    after      = \vspace{-\baselineskip}
  }

\begin{document}

\begin{table}
\centering
\setlist[itemize]{noitemsep}
\begin{tabular}{m{2cm}|m{2cm}}\hline
    a & \begin{tabular-list}
        \item B
        \item C
        \item D
    \end{tabular-list}\\\hline
    e & \begin{tabular-list}
        \item F
        \item G
        \item H
    \end{tabular-list}\\\hline
\end{tabular}
\end{table}

\end{document}

Output of the above code

F. Pantigny
  • 40,250
1

With tabularray package is simple:

\documentclass{article}

\usepackage{tabularray} \usepackage{enumitem}

\begin{document} \begin{table}[ht] \begin{tblr}{hlines, vline{2}, colspec = { {2}{Q[l, m, wd=22mm]} }, stretch = -1,%<--- remove extra space above and below lists % with nosep option; doc p.51 tabularray rowsep = 3pt } a & \begin{itemize}[nosep, leftmargin=] \item B \item C \item D \end{itemize} \ e & \begin{itemize}[nosep, leftmargin=*] \item F \item G \item C \end{itemize} \ \end{tblr} \end{table} \end{document}

enter image description here

Addendum}:
At tabular table desired result you can get also with:

\documentclass{article}

\usepackage{array} \usepackage{enumitem} \AtBeginEnvironment{table}{% global settings for itemize in table floats \setlist[itemize]{nosep, leftmargin=*, label=\textbullet, before={\begin{minipage}[t]{\hsize}},%https://tex.stackexchange.com/questions/531952/ after ={\end{minipage}} } }% end of \AtBeginEnvironment

\begin{document} \begin{table}[ht] \begin{tabular}{m{22mm}|m{22mm}} \hline a & \begin{itemize} \item B \item C \item D \end{itemize} \ \hline e & \begin{itemize} \item F \item G \item C \end{itemize} \ \hline \end{tabular} \end{table} \end{document}

Result is similar as before

Zarko
  • 296,517