4

Q: How can I create a table which contains a continuous numerating list with each item in a new row. So I can insert content for the other columns in that row.
I use luatex.
The result should look like this (Word): Picture of word table I tried it with enumerate and came up this idea which doesn´t work (look at the comments)(shortened content):

\documentclass[8pt,a4paper]{extarticle}

\usepackage{array}
\usepackage{enumitem}
\usepackage{tabularx}
\usepackage[left=1.2cm, right=1.2cm, top=0.0cm, bottom=0.0cm, headheight=37pt, includeheadfoot]{geometry}

\begin{document}

\begin{tabularx}{\textwidth}{p{8cm}|X|X|X|X|X|}
    \textbf{Bezeichnung} & \textbf{Einzelpreis} & \textbf{Anzahl}
    & \textbf{Intervall} & \textbf{Rabatt} & \textbf{€/Monat}\\
    \hline%<----->
    \begin{enumerate}[label=\Roman*,noitemsep]
        \item System: Software as a Service  Geltungsbereich Arbeits- und
        Gesundheitsschutz % &40,00€ & 1&Laufzeit &10\% &36,00€ \\ <--- Idea but doesn´t work...
        \item IT-Service-Pack Release, Update, Support:\newline
        Übernahme der kompletten IT-Administration und weitere Dienstleistungen
        \item Management: Auswahl-, Bestellung-, Überwachungs- und
        \item Audit zur Evaluation und Qualitätssicherung %& 7,39€ & 1 & Laufzeit & 10\% & 6,46€ \\ <--- I need smth like this...
    \end{enumerate} &40,00€ & 1&Laufzeit &10\% &36,00€ \\ %<---- Only this works
    \hline%<----->
    Summe & & & & &36,46€ \\
\end{tabularx}

\end{document}

which looks like this: Table created in Latex

  • Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. Please help us help you and add a minimal working example (MWE) that illustrates your problem. Reproducing the problem and finding out what the issue is will be much easier when we see compilable code, starting with \documentclass{...} and ending with \end{document}. – Alessandro Cuttin Jul 19 at 9:36
  • And, what is the question, btw? – Alessandro Cuttin Jul 19 at 9:36
  • Hi, thanks for your comment. I edited the question and provided a working code snippet. – Felix B. Jul 19 at 9:50
  • Do you mean different items should be in different table rows? – Bernard Jul 19 at 9:54
  • @Bernard as of my understanding, the OP wants all columns should be in top alignment, if not so, he may correct me ... – MadyYuvi Jul 19 at 10:01
1

Building upon Bernard's solution and the magicrownumber from here:

enter image description here

\documentclass[8pt,a4paper]{extarticle}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{xcolor}
\usepackage{tabularx}
\usepackage[left=1.2cm, right=1.2cm, top=0.0cm, bottom=0.0cm, headheight=37pt, includeheadfoot]{geometry}
\makeatletter
\newcommand*{\compress}{\@minipagetrue}
\makeatother
\usepackage{makecell}
 \renewcommand{\theadfont}{\color{black}\bfseries}

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

\begin{document}
\sffamily
\setlength{\extrarowheight}{2pt}
\noindent\begin{tabularx}{\textwidth}{@{\makebox[3em][r]{\rownumber\space}\compress}X|>{\color{red}}c|c|c|*{2}{>{\color{red}}c|}}
\multicolumn{1}{l|}{\textbf{Bezeichnung}} & \thead{Einzelpreis} & \textbf{Anzahl}
& \textbf{Intervall} & \thead{Rabatt} & \thead{€/Monat}\\
\hline
     System: Software as a Service Geltungsbereich Arbeits- und
    Gesundheitsschutz  &40,00€ & 1&Laufzeit &10\% &36,00€ \\ 
     IT-Service-Pack Release, Update, Support:\newline
    Übernahme der kompletten IT-Administration und weitere Dienstleistungen & & & & & \\
     Management: Auswahl-, Bestellung-, Überwachungs- und & & & & & \\
     Audit zur Evaluation und Qualitätssicherung & 7,39€ & 1 & Laufzeit & 10\% & 6,46€ \\ 
\hline
\multicolumn{1}{l|}{Summe} & & & & &36,46€ 
\end{tabularx}
\vskip1cm



\end{document}

The counter magicrownumber is automatically reset at the start of a tabular, so in a new tabular environment, teh counter will start from I again. If you wish to reset the counter inside of a tabular environment you can use \setcounter{magicrownumner}{0} as shown in the following example:

enter image description here

\documentclass[8pt,a4paper]{extarticle}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{xcolor}
\usepackage{tabularx}
\usepackage[left=1.2cm, right=1.2cm, top=0.0cm, bottom=0.0cm, headheight=37pt, includeheadfoot]{geometry}
\makeatletter
\newcommand*{\compress}{\@minipagetrue}
\makeatother
\usepackage{makecell}
 \renewcommand{\theadfont}{\color{black}\bfseries}

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

\begin{document}
\sffamily
\setlength{\extrarowheight}{2pt}
\noindent\begin{tabularx}{\textwidth}{@{\makebox[3em][r]{\rownumber\space}\compress}X|>{\color{red}}c|c|c|*{2}{>{\color{red}}c|}}
\multicolumn{1}{l|}{\textbf{Bezeichnung}} & \thead{Einzelpreis} & \textbf{Anzahl}
& \textbf{Intervall} & \thead{Rabatt} & \thead{€/Monat}\\
\hline
     System: Software as a Service Geltungsbereich Arbeits- und
    Gesundheitsschutz  &40,00€ & 1&Laufzeit &10\% &36,00€ \\ 
     IT-Service-Pack Release, Update, Support:\newline
    Übernahme der kompletten IT-Administration und weitere Dienstleistungen & & & & & \\
     Management: Auswahl-, Bestellung-, Überwachungs- und & & & & & \\
     Audit zur Evaluation und Qualitätssicherung & 7,39€ & 1 & Laufzeit & 10\% & 6,46€ \\ 
\hline
\multicolumn{1}{l|}{Summe} & & & & &36,46€ 
\end{tabularx}

\bigskip

\noindent\begin{tabularx}{\textwidth}{@{\makebox[3em][r]{\rownumber\space}\compress}X|>{\color{red}}c|c|c|*{2}{>{\color{red}}c|}}
\multicolumn{1}{l|}{\textbf{Bezeichnung}} & \thead{Einzelpreis} & \textbf{Anzahl}
& \textbf{Intervall} & \thead{Rabatt} & \thead{€/Monat}\\
\hline
     System: Software as a Service Geltungsbereich Arbeits- und
    Gesundheitsschutz  &40,00€ & 1&Laufzeit &10\% &36,00€ \\ 
     IT-Service-Pack Release, Update, Support:\newline
    Übernahme der kompletten IT-Administration und weitere Dienstleistungen & & & & & \\
     Management: Auswahl-, Bestellung-, Überwachungs- und & & & & & \\
     Audit zur Evaluation und Qualitätssicherung & 7,39€ & 1 & Laufzeit & 10\% & 6,46€ \\ 
\hline
\multicolumn{1}{l|}{Summe} & & & & &36,46€ 
\end{tabularx}


\bigskip


\noindent\begin{tabularx}{\textwidth}{@{\makebox[3em][r]{\rownumber\space}\compress}X|>{\color{red}}c|c|c|*{2}{>{\color{red}}c|}}
\multicolumn{1}{l|}{\textbf{Bezeichnung}} & \thead{Einzelpreis} & \textbf{Anzahl}
& \textbf{Intervall} & \thead{Rabatt} & \thead{€/Monat}\\
\hline
     System: Software as a Service Geltungsbereich Arbeits- und
    Gesundheitsschutz  &40,00€ & 1&Laufzeit &10\% &36,00€ \\ 
     IT-Service-Pack Release, Update, Support:\newline
    Übernahme der kompletten IT-Administration und weitere Dienstleistungen & & & & & \\
     Management: Auswahl-, Bestellung-, Überwachungs- und & & & & & \\
     Audit zur Evaluation und Qualitätssicherung & 7,39€ & 1 & Laufzeit & 10\% & 6,46€ \setcounter{magicrownumbers}{0}\\ %<-------- Reset counter
\hline 
     System: Software as a Service Geltungsbereich Arbeits- und
    Gesundheitsschutz  &40,00€ & 1&Laufzeit &10\% &36,00€ \\ 
     IT-Service-Pack Release, Update, Support:\newline
    Übernahme der kompletten IT-Administration und weitere Dienstleistungen & & & & & \\
     Management: Auswahl-, Bestellung-, Überwachungs- und & & & & & \\
     Audit zur Evaluation und Qualitätssicherung & 7,39€ & 1 & Laufzeit & 10\% & 6,46€ \\
\hline
\multicolumn{1}{l|}{Summe} & & & & &36,46€
z\end{tabularx}

\end{document}
  • 1
    Thanks for answering :) This is the easiest solution that solved my problem. – Felix B. Jul 23 at 11:28
  • I have another question... How can I break the enumeration? I have this table two times in my document and in each table should have I,II,III,IV... – Felix B. Jul 26 at 13:14
  • @FelixB.: The counter is reset automatically if you use a new tabular or tabularx environment. If you want to reset the counter within the same environment, you can use \setcounter{magicrownumner}{0}. I have edited my anser to include a MWE that demonstrates both situations. I hope I have answered your question with that. – leandriis Jul 26 at 14:07
4

Similarly to @Bernard answer, but some details are different:

  • for the first column is defined column type E for enumerated contents:
\makeatletter
\newcommand*{\compress}{\@minipagetrue}
\makeatother
\newcolumntype{E}[1]{ >{\compress\enumerate}p{#1}<{\endenumerate}}

which simplified writing lists in the first column

  • for enumerate list is defined the following setup:
\setlist[enumerate]{%
                 resume=column,
                 nosep,
                 label=\Roman*.,
                 leftmargin=*,
                 after=\vspace*{-\dimexpr\baselineskip + \partopsep}}
  • for resuming enumeration of list is used option resume=column, in enumerate list set up
  • for start enumeration at I. is dedicated \setcounter{enumi}{0} before first \item in column (see MWE below)
  • I didn't bother with coloring numbers (it wasn't clear to me, if in some column all number are red, or they are select according to some other criteria)
  • for compilation is used xelatex (due to use € characters for currency)

    Complete MWE is:

\documentclass[8pt,a4paper]{extarticle}
\usepackage[hmargin=1.2cm, vmargin=0.0cm, 
            headheight=37pt, includeheadfoot]{geometry}
\usepackage{enumitem}
\usepackage{ragged2e}
\usepackage{tabularx}

\makeatletter
\newcommand*{\compress}{\@minipagetrue}
\makeatother
\newcolumntype{E}[1]{ >{\compress\enumerate}p{#1}<{\endenumerate}}
\newcommand*\mcbf[1]{\multicolumn{1}{>{\bfseries}l|}{#1}}

\begin{document}

\setlist[enumerate]{  label=\Roman*.,
                 nosep,
                 leftmargin=*,
                 after=\vspace*{-\dimexpr\baselineskip + \partopsep}}
\begin{tabularx}{\linewidth}{ >{\RaggedRight}E{5cm}*{5}{|X}|}
\mcbf{Bezeichnung}    
    & \mcbf{Einzelpreis}    & \mcbf{Anzahl}   & \mcbf{Intervall} 
    & \mcbf{Rabatt}         & \mcbf{€/Monat}\\
    \hline%<----->
    \setcounter{enumi}{0}
\item   System: Software as a Service  Geltungsbereich Arbeits- und Gesundheitsschutz
    & 40,00€    & 1     & Laufzeit  & 10\%  & 36,00€    \\ 
\item   IT-Service-Pack Release, Update, Support: 

        Übernahme der kompletten IT-Administration und weitere Dienstleistungen
\item Management: Auswahl-, Bestellung-, Überwachungs- und
\item Audit zur Evaluation und Qualitätssicherung 
    & 7,39€     & 1     & Laufzeit  & 10\%  & 6,46€     \\ 
    \hline%<----->
\mcbf{Summe}
    &           &       &           &       & 36,46€    \\
\end{tabularx}

\end{document}

enter image description here

addendum: initiated by conversation with @Bernard (in comments below) see if the following variation of mine original answer is more appropriate for you:

  • definition of the enumerate style in tables is moved in preamble, where is now available to all lists in table
  • for the first column is used X column type
  • for columns with numbers are used S columns defined in the siunitx package
  • your table is encapsulated in table floating environment.
  • added are red colors for the second, fifth and six (last) column
\documentclass[8pt,a4paper]{extarticle}
\usepackage[hmargin=1.2cm, vmargin=0.0cm,
            headheight=37pt, includeheadfoot]{geometry}
\usepackage{enumitem}
\usepackage{etoolbox}      % new 
\AtBeginEnvironment{table}{% for enumerate list in "table" environments
\setlist[enumerate]{%      % moved in preamble 
                 resume=column,
                 nosep,
                 label=\Roman*.,
                 leftmargin=*,
                 after=\vspace*{-\dimexpr\baselineskip + \partopsep}}
                            }
\usepackage{ragged2e}
\usepackage{tabularx}
\usepackage{xcolor}
\usepackage{siunitx}

\makeatletter
\newcommand*{\compress}{\@minipagetrue}
\makeatother
\newcolumntype{E}{ >{\compress\enumerate}X<{\endenumerate}}
\newcommand*\mcbf[1]{\multicolumn{1}{>{\bfseries}l|}{#1}}

\begin{document}
    \begin{table}
\begin{tabularx}{\linewidth}{@{}
            >{\RaggedRight}E
            |S[table-format=2.2,color=red]<{\,\textcolor{red}{€}}
            |S[table-format=1.0]
            |l
            |S[table-format=2.0,color=red]<{\,\textcolor{red}{\%}}
            |S[table-format=2.2,color=red]<{\,\textcolor{red}{€}}|
                            }
\mcbf{Bezeichnung}
    & \mcbf{Einzelpreis}    & \mcbf{Anzahl}   & \mcbf{Intervall}
    & \mcbf{Rabatt}         & \mcbf{€/Monat}\\
    \hline
    \setcounter{enumi}{0}       % <--- reset counter enumi
\item   System: Software as a Service  Geltungsbereich Arbeits- und Gesundheitsschutz
    & 40,00     & 1     & Laufzeit  & 10            & 36,00 \cr % <---
    \setcounter{enumi}{1}
\item   IT-Service-Pack Release, Update, Support:

        Übernahme der kompletten IT-Administration und weitere Dienstleistungen
\item Management: Auswahl-, Bestellung-, Überwachungs- und
\item Audit zur Evaluation und Qualitätssicherung
    & 7,39      & 1     & Laufzeit  & 10            & 6,46 \cr % <---
    \hline%<----->
\mcbf{Sume}
    & \mcbf{}   &       &           & \mcbf{}       & 36,46 \cr % <---\
\end{tabularx}
    \end{table}
\end{document}

enter image description here

  • @Bernard, ups, there should be \endenumereate. Corrected now. – Zarko Jul 19 at 13:27
  • If I may, I think the option wide=0pt is better in tables (spoils less horizontal space)? perhaps also you should create a new tableenum list, or something like that, to make the configuration purely local to lists inside tables? – Bernard Jul 19 at 13:32
  • @Bernard, it can be done as you suggest. Now the list settings is walit only for this table. If OP have more similar table, your suggestion is far better (I will wrote addendum with this). I first try to use wide=0pt, but to my opinion in the result the items numbers are than less visible. As table is now, I rather use X column type for the first column, and S` columns for other except for clumn with head Intervall. – Zarko Jul 19 at 13:46
  • I also used X, but I must say I didn't even think of the S column type. That's an excellent idea! – Bernard Jul 19 at 14:14
  • Thanks for answering :) @Zarko – Felix B. Jul 23 at 11:31
4

I propose one of these two solutions:

\documentclass[8pt,a4paper]{extarticle}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{xcolor}
\usepackage{enumitem}
\usepackage{tabularx}
\usepackage[left=1.2cm, right=1.2cm, top=0.0cm, bottom=0.0cm, headheight=37pt, includeheadfoot]{geometry}
\makeatletter
\newcommand*{\compress}{\@minipagetrue}
\makeatother
\usepackage{makecell}
 \renewcommand{\theadfont}{\color{black}\bfseries}
\usepackage{listliketab}

\begin{document}
\sffamily
\setlength{\extrarowheight}{2pt}
\noindent\begin{tabularx}{\textwidth}{>{\compress}X|>{\color{red}}c|c|c|*{2}{>{\color{red}}c|}}
\textbf{Bezeichnung} & \thead{Einzelpreis} & \textbf{Anzahl}
& \textbf{Intervall} & \thead{Rabatt} & \thead{€/Monat}\\
\hline%<----->
\begin{enumerate}[label=\Roman*. ,widest =VI, noitemsep, wide=0pt, leftmargin=*, after =\vspace*{-\dimexpr\topsep + \partopsep}]
    \item System: Software as a Service Geltungsbereich Arbeits- und
    Gesundheitsschutz % &40,00€ & 1&Laufzeit &10\% &36,00€ \\ <--- Idea but doesn´t work...
    \item IT-Service-Pack Release, Update, Support:\newline
    Übernahme der kompletten IT-Administration und weitere Dienstleistungen
    \item Management: Auswahl-, Bestellung-, Überwachungs- und
    \item Audit zur Evaluation und Qualitätssicherung %& 7,39€ & 1 & Laufzeit & 10\% & 6,46€ \\ <--- I need smth like this...
\end{enumerate} &40,00€ & 1&Laufzeit &10\% &36,00€ \\ %<---- Only this works
\hline%<----->
Summe & & & & &36,46€ 
\end{tabularx}
\vskip1cm

\storestyleof{enumerate}
\begin{listliketab}
\newcounter{tabenum}\setcounter{tabenum}{0}
\newcommand{\nextnum}{\addtocounter{tabenum}{1}\Roman{tabenum}.}
\noindent\begin{tabularx}{\textwidth}{LX|>{\color{red}}c|c|c|*{2}{>{\color{red}}c|}}
    \multicolumn{2}{l|}{\textbf{Bezeichnung}} & \thead{Einzelpreis} & \textbf{Anzahl}
    & \textbf{Intervall} & \thead{Rabatt} & \thead{€/Monat}\\
    \hline\noalign{\vskip-1.8ex}%<----->
\nextnum & System: Software as a Service Geltungsbereich Arbeits- und
        Gesundheitsschutz &40,00€ & 1&Laufzeit &10\% &36,00€ \\[-3ex]
\nextnum & IT-Service-Pack Release, Update, Support:\newline
        Übernahme der kompletten IT-Administration und weitere Dienstleistungen & & & & & \\[-3ex]
\nextnum &Management: Auswahl-, Bestellung-, Überwachungs- und & & & & & \\[-3ex]
\nextnum & Audit zur Evaluation und Qualitätssicherung & 7,39€ & 1 & Laufzeit & 10\% & 6,46€ \\
\hline
\multicolumn{2}{l|}{Summe} & & & & &36,46€
\end{tabularx}
\end{listliketab}

\end{document} 

enter image description here

  • 1
    Wow...such a nice suggestion... – MadyYuvi Jul 19 at 11:10
  • Thanks for answering :) @Bernard – Felix B. Jul 23 at 11:31

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.