1

Consider the following Minimum Working Example (MWE):

\documentclass{article}
\usepackage{enumitem}
\usepackage{tabularx}

\begin{document}

    \begin{tabularx}{\textwidth}{| p{2cm} | p{2cm} |}
        Text &  \begin{itemize}
                    \item Text
                    \item Text
                \end{itemize}
                \\
    \end{tabularx}

\end{document}

Screenshot of the result:

Screenshot of the result


Description of the issue:

The behavior of \itemize to let its items begin in a new line looks ugly in this case.

How could I get it like this?

Screenshot of the desired state

I would prefer to avoid using a messy \vspace{-...pt} with hardcoded values to shift the items up.

Dave
  • 3,758

2 Answers2

5

There is a macro I found on this site,which makes LaTeX believe the cell is a minipage. However, there remains a vertical spacing at the bottom of the cell. This problem can be solved with enumitem, adding a negative vertical spacing at the end of the list. In addition, I advise to use the option wide=0pt in tables:

\documentclass{article}
\usepackage{enumitem}
\usepackage{tabularx}
\makeatletter
\newcommand*{\compress}{\@minipagetrue}
\makeatother
\begin{document}
\begin{tabularx}{.5\textwidth}{|X | >{\compress}X|}

Some text & Some more other\ Text & \begin{itemize}[wide=0pt, leftmargin=, nosep, after =\vspace{-\baselineskip}] \item Text \item Text \end{itemize} \ Another text & Still another \end{tabularx}

\end{document}

enter image description here

Bernard
  • 271,350
  • Could it be that some characters slipped into the first line of your example source after you compiled the shown result? (& Some A SCAmore ...)? Just a tiny thing you might wanna fix to not confuse noobies like me - otherwise beatiful and useful solution :) – MaxAxeHax Mar 31 '21 at 17:26
  • 1
    @MaxAxeHax: Looks very much like a copy-paste accident. I don't always think of checking. Thank you for warning me! – Bernard Mar 31 '21 at 17:30
3
\documentclass{article}
\usepackage{enumitem}
\usepackage{tabularx}

\begin{document}

    \begin{tabularx}{\textwidth}{| p{2cm} | p{2cm} |}
        Text &\csname @minipagetrue\endcsname  \begin{itemize}
                    \item Text
                    \item Text
                \end{itemize}
                \\
    \end{tabularx}

\end{document}

enter image description here

Ulrike Fischer
  • 327,261