0

I would like to find a way how to create such table design using longtable:

My plan fails on point when I actually cant find the right syntax of where to initializace/terminate the \longtable and \enumerate environments, so I am out of my league here completely.

Any help would be much appreciated, I already learned a lot here and hopefully would be able to transfer that information further :) Even pointing in right direction would be great.

Thanks in advance, Tomáš

2

Here is a quite automated solution:

\documentclass{article}

\usepackage{longtable}

\usepackage{etoolbox,array}
\preto\tabular{\setcounter{magicrownumbers}{0}}
\newcounter{magicrownumbers}
\newcommand\rownumber{\stepcounter{magicrownumbers}\arabic{magicrownumbers}}

\usepackage{enumitem}
\newlist{tabenumi}{enumerate}{2}
  \setlist[tabenumi,1]{label={\themagicrownumbers.\arabic*},nosep,leftmargin=*,before=\vspace{-\baselineskip},after=\vspace{-\baselineskip}}
  \setlist[tabenumi,2]{label={\textbullet},nosep,leftmargin=*}
\newlist{tabitemize}{itemize}{1}
  \setlist[tabitemize]{label=\textbullet,nosep,leftmargin=*,after=\vspace{-\baselineskip}}


\usepackage{calc}
\newlength{\mycolumnwidth}
\setlength{\mycolumnwidth}{\textwidth-4\tabcolsep-4\arrayrulewidth-2em}

\begin{document}

\begin{longtable}{|@{\makebox[2em][l]{\space\rownumber.}} |p{0.5\mycolumnwidth} |p{0.5\mycolumnwidth}|}
\hline
 Some prety long text including itemize 
  \begin{tabitemize}
   \item an item
   \item another item
  \end{tabitemize}
& Another long text that can contain linebreaks\\
\hline
 \begin{tabenumi}[series=test]
  \item  item
     \begin{tabenumi}
     \item item
     \item item
     \end{tabenumi}
   \item  item Additional text
     \begin{tabenumi}
     \item item
     \item item
     \end{tabenumi}
  \end{tabenumi}
& Additional text to 2.1 \vspace{2\baselineskip}\newline  Additional text to 2.2\\
\hline
\end{longtable}

\end{document}

enter image description here

The row numbers in the table are generated automatically. The code for this is borrowed from here and slightly modified.

I have used the enumitem package in order to create two new enumerate- and itemize-like lists for the use in table cells. The first level of tabenumi behaves like an enumerate environment and automatically adds the rownumber (left column) to its numbering scheme. The second level of tabenumi behaves like an itemize environment and uses a \textbullet insetad of a number.

The tabitemize environment is intended to use without a surrounding tabenumi environment as shown in the first row of the table.

Lastly, I have defined a new length in oder to calculate the column widths that are necessary to make the table as wide as the textwidth.


For a more open look of the table, you might also want to consider deleting all vertical lines and replace the \hlines by horizontal rules from the booktabs package. In the following example, I have marked all the lines with changes compared to the first example, with %<----------.

\documentclass{article}

\usepackage{longtable}

\usepackage{etoolbox,array}
\preto\tabular{\setcounter{magicrownumbers}{0}}
\newcounter{magicrownumbers}
\newcommand\rownumber{\stepcounter{magicrownumbers}\arabic{magicrownumbers}}

\usepackage{enumitem}
\newlist{tabenumi}{enumerate}{2}
  \setlist[tabenumi,1]{label={\themagicrownumbers.\arabic*},nosep,leftmargin=*,before=\vspace{-\baselineskip},after=\vspace{-\baselineskip}}
  \setlist[tabenumi,2]{label={\textbullet},nosep,leftmargin=*}
\newlist{tabitemize}{itemize}{1}
  \setlist[tabitemize]{label=\textbullet,nosep,leftmargin=*,after=\vspace{-\baselineskip}}


\usepackage{calc}
\newlength{\mycolumnwidth}
\setlength{\mycolumnwidth}{\textwidth-4\tabcolsep-2em} %<----------

\usepackage{booktabs} %<----------

\begin{document}

\begin{longtable}{@{\makebox[2em][l]{\space\rownumber.}} p{0.5\mycolumnwidth} p{0.5\mycolumnwidth}} %<----------
\toprule %<----------
 Some prety long text including itemize 
  \begin{tabitemize}
   \item an item
   \item another item
  \end{tabitemize}
& Another long text that can contain linebreaks\\
\midrule %<----------
 \begin{tabenumi}[series=test]
  \item  item
     \begin{tabenumi}
     \item item
     \item item
     \end{tabenumi}
   \item  item Additional text
     \begin{tabenumi}
     \item item
     \item item
     \end{tabenumi}
  \end{tabenumi}
& Additional text to 2.1 \vspace{2\baselineskip}\newline  Additional text to 2.2\\
\bottomrule %<----------
\end{longtable}

\end{document}

enter image description here

  • Thank you so much! I have to look into the package \enumitem to learn how to utilizate it, looks very usefull! Sadly I am now at work and cant analyze the code thoroughly, but its working perfectly! I look into \booktabs for sure, at first the package documentation seemed a bit complicated to me, as being new to TeX :) – Tomáš Kruliš Jun 14 '18 at 7:26
  • @TomášKruliš: You're welcome. I have edited my code to also contain an example using booktabs. If you have further questions regarding the examples or need explanation on how the code works, please feel free to ask. – leandriis Jun 14 '18 at 9:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.