3

I am creating a table in which I have cells containing itemize environments. For a given row I have either zero or two cells containing this environment and working together. However the text for the items of the first cell is usually longer than the text for the items of the second cell.

I am looking for a way to implement this table with the bullet points of the items being respectively at the same height. A picture being better than a long description, here it is:

Problem

I would like the bullet point of Short 1 to be at the same level as the one from the first long item, and the same goes for Short 2 and its related item.

Here is the code used to produce this table:

\documentclass{article}

\usepackage{enumitem}
\usepackage{array}

\begin{document}

\begin{table}[H]
\begin{center}
\begin{tabular}{| m{0.3cm} | m{5.5cm} | m{4cm} | m{1.8cm} | m{1cm}|}
\hline
 1 &
\begin{itemize}[leftmargin=0.3cm]\itemsep0pt
\item This is a first long long long item, spanning on two lines
\item And here comes a second one lon long item
\end{itemize} & Some text which can be either long or short, there is no general rule & 
\begin{itemize}[leftmargin=0.3cm]\itemsep0pt
\item Short 1
\item Short 2
\end{itemize} & Some short text\\ \hline
\end{tabular}
\end{center}
\end{table}

\end{document}

NOTE 1 I would like a solution as compact in height as possible

NOTE 2 I am using the m{<value>} column style because the longest cell for a different rows is not always the same.

NOTE 3 I am aware that the Table is ugly and the vertical lines should be removed to match more to a more readable and reader-friendly solution but this is a mandatory template... Too bad...

EDIT Trylks proposed to use a combination of \multirow in the non-list cell and to split the list cells in more cells. This does fix the problem of the vertical alignment of the items but it also creates misalignments for the other cells.

MWE for the Edit suggestion

\documentclass{article}

\usepackage{enumitem}
\usepackage{array}
\usepackage{multirow}

\begin{document}

\begin{table}[H]
\begin{center}
\begin{tabular}{| m{0.3cm} | m{5.5cm} | m{4cm} | m{1.8cm} | m{1cm}|}
\hline
\multirow{2}{*}{1} & 
\begin{itemize}[leftmargin=0.3cm]
\item This is a first long long long item, spanning on two lines
\end{itemize}
& \multirow{2}{*}{Some text which can be either long or short, there is no general rule} & 
\begin{itemize}[leftmargin=0.3cm]\itemsep0pt
\item Short 1
\end{itemize}
& \multirow{2}{*}{Some short text}\\
& \begin{itemize}[leftmargin=0.3cm]
\item And here comes a second one lon long item
\end{itemize}
& &
\begin{itemize}[leftmargin=0.3cm]
\item Short 2
\end{itemize}
& \\ \hline
\end{tabular}
\end{center}
\end{table}

\end{document}

And the corresponding output:

Output2

EDIT 2 jfbu proposed a solution which seems to work (see his answer) for the above case but it is just a coincidence. If one item has a text longer than two lines, it crashes also. See the MWE and its output:

\documentclass{article}

\usepackage{enumitem}
\usepackage{array}

\begin{document}

\begin{table}[H]
\begin{center}
\begin{tabular}{| m{0.3cm} | m{5.5cm} | m{4cm} | m{1.8cm} | m{1cm}|}
\hline
 1 &
\begin{itemize}[leftmargin=0.3cm]\itemsep0pt
\item \strut This is a first long long long item, spanning on two lines. This is a first long long long item, spanning on two lines. This is a first long long long item, spanning on two lines \strut
\item \strut And here comes a second one lon long item \strut
\end{itemize} & Some text which can be either long or short, there is no general rule & 
\begin{itemize}[leftmargin=0.3cm]\itemsep0pt
\item \strut Short 1 \hfill\break \strut
\item \strut Short 2 \hfill\break \strut
\end{itemize} & Some short text\\ \hline
\end{tabular}
\end{center}
\end{table}

\end{document}

Output Edit 2

Moriambar
  • 11,466
Ludovic C.
  • 8,888
  • 1
    What about using multirow in the cells with no items and several cells where the items are? That's probably the easiest way to align vertically several items as you seem to propose. – Trylks Oct 04 '13 at 10:37
  • @Trylks Yes and no. It does solve the problem to get the items at the same level, however it introduces other problem for the cells containing the \multirow. They are vertically centered any more and for the one in the middle (the long text), it does not break the line when required and overlays the cell next to it. – Ludovic C. Oct 04 '13 at 11:01
  • I'd use top alignment; one uses bulleted lists when the items' order is not really important, so this usage suggests that the first item in the second column has no relationship with the first item in the fourth column. – egreg Oct 04 '13 at 12:16
  • I think those problems can be solved by other means, e.g. Text wrap in tables (multirow package loaded). There may be better solutions, though, so I wish you luck. – Trylks Oct 04 '13 at 12:47

1 Answers1

2

I still recommend \strut's.

\documentclass{article}

\usepackage{enumitem}
\usepackage{array}

\makeatletter
\def\LUDOVIC {}
\def\LUDOvic {\par\xdef\LUDOVIC{\LUDOVIC {\the\prevgraf}}}
\def\ludoVIC {\par\expandafter\ludovic@ \LUDOVIC\relax }
\def\ludovic@ #1#2\relax {\gdef\LUDOVIC {#2}%
   \vspace{\numexpr #1-\prevgraf\relax\baselineskip}}
\makeatother


\begin{document}

\begin{table}[H]
\begin{center}
\begin{tabular}{| m{0.3cm} | m{5.5cm} | m{4cm} | m{1.8cm} | m{1cm}|}
\hline
 1 &
\begin{itemize}[leftmargin=0.3cm]\itemsep0pt
\item This is a first long long long item, spanning on many
  lines. This is a first long long long item, spanning on many 
  lines. This is a first long long long item, spanning on many 
  lines. This is a first long long long item, spanning on many 
  lines. \LUDOvic 
\item  And here comes a second one long long
  item. And here comes a second one long long
  item. And here comes a second one long long
  item. And here comes a second one long long
  item. And here comes a second one long long
  item. \LUDOvic
\item And here is a third one.  And here is a third one.  And here is a third
  one.  And here is a third one.  And here is a third one. \LUDOvic
\item And a fourth one. \LUDOvic
\end{itemize} & Some text which can be either long or short, there is no general rule & 
\begin{itemize}[leftmargin=0.3cm]\itemsep0pt
\item Short 1\ludoVIC
\item Short 2\ludoVIC
\item Short 3\ludoVIC
\item Short 4\ludoVIC
\end{itemize} & Some short text\\ \hline
\end{tabular}
\begin{tabular}{| m{0.3cm} | m{5.5cm} | m{4cm} | m{1.8cm} | m{1cm}|}
\hline
 1 &
\begin{itemize}[leftmargin=0.3cm]\itemsep0pt
\item This is a first long long long item, spanning on many
  lines. This is a first long long long item, spanning on many 
  lines. \LUDOvic 
\item  And here comes a second one long long
  item. And here comes a second one long long
  item. And here comes a second one long long
  item. \LUDOvic
\end{itemize} & Some text which can be either long or short, there is no general rule & 
\begin{itemize}[leftmargin=0.3cm]\itemsep0pt
\item Short 1\ludoVIC
\item Short 2\ludoVIC
\end{itemize} & Some short text\\ \hline
\end{tabular}
\end{center}
\end{table}

\end{document}

Output:

tables with items


First quickly drafted answer:

This seems to work.

\documentclass{article}

\usepackage{enumitem}
\usepackage{array}

\begin{document}

\begin{table}[H]
\begin{center}
\begin{tabular}{| m{0.3cm} | m{5.5cm} | m{4cm} | m{1.8cm} | m{1cm}|}
\hline
 1 &
\begin{itemize}[leftmargin=0.3cm]\itemsep0pt
\item \strut This is a first long long long item, spanning on two lines\strut
\item \strut And here comes a second one lon long item\strut
\end{itemize} & Some text which can be either long or short, there is no general rule & 
\begin{itemize}[leftmargin=0.3cm]\itemsep0pt
\item \strut Short 1\hfill\break \strut
\item \strut Short 2\hfill\break \strut
\end{itemize} & Some short text\\ \hline
\end{tabular}
\end{center}
\end{table}

\thispagestyle{empty}
\end{document}

table

  • It seems to work for the cases with only two lines (maximum) per items. See the edit of my question for the problem with longer texts. – Ludovic C. Oct 04 '13 at 11:43