1

I am trying to create a form for orders. The heart of this document is a srclttr2 with a longtable to even get a nice document for long orders. To make this template more flexible/easy I would like to fill the table via one command. This works quiet well except two points.

  1. I would like to alternately change the color of the horizontal line between two rows. For this I introduced a counter that determines the line colour at the end of the command with an if-else statement and increments the counter. Unfourtnately this leads to an "Missing \endcsname inserted." error. I have a feeling that this problem is related to expanding and executing in TEX, but I don't have a clue where the problem might be. Maybe it is also related to the use of the siunitx package?
  2. The second problem occurs, when I try to make the third parameter of my command, the unit of the order amount, optional. So I thought my command should look similar to this: \newcommand{\addOrderRow}[8][\si{\piece}]{\sisetup{round-precision=0} #2 & #3 & #1 & \begin{minipage}[t]{78mm}{\setlength{\parskip}{.2mm}\begin{description}\item[{#4}]#5\end{description}\vspace{.2mm}}\end{minipage} & #6 & #7 & #8 & \percent \\ \pagebreak[3]}. In this case I got the error message "Use of \LT@array doesn't match its definition.". I think I am doing something fundamentally wrong, but I don't know what.

Can anyone tell me why the above considerations do not work in conjunction with a (long)table?

\documentclass[10pt]{scrlttr2}

\usepackage[ngerman]{babel}
\usepackage[utf8]{inputenc}
\usepackage{helvet}
\renewcommand{\familydefault}{\sfdefault}
\usepackage[locale=DE]{siunitx}
\sisetup{
    locale = DE,
    %number-mode = text,
    %text-family-to-math = true,
    detect-all,
    round-mode = places, %default: none
    round-precision = 2
}
\usepackage{longtable}
\usepackage{collcell}
\usepackage{colortbl}
\usepackage{xcolor}
%\usepackage{microtype} 

\setlength{\tabcolsep}{3pt}
\DeclareSIUnit{\piece}{Stk.}

\newcommand{\tablemidlinea}{\arrayrulecolor{lightgray}\hline\arrayrulecolor{black}}
\newcommand{\tablemidlineb}{\arrayrulecolor{red}\hline\arrayrulecolor{black}}

\newcounter{rownum}

\newcommand{\addOrderRow}[8]{
    \sisetup{round-precision=0} #1 &% postion
    #2 &% quantity 
    #3 &% unit
    \begin{minipage}[t]{78mm}{\setlength{\parskip}{.2mm}\begin{description}\item[{#4}]#5\end{description}\vspace{.2mm}}\end{minipage} &% number + description
    #6 &% price
    #7 &% amount
    #8 &% tax
    \percent% 
    \\ \pagebreak[3]%
    \ifodd\value{rownum}%
        \tablemidlinea%
    \else%
        \tablemidlineb%
    \fi%
    \stepcounter{rownum}%
}


\begin{document}
\begin{letter}


\setcounter{rownum}{3}

\begin{longtable}{
S[table-format = 2.0]|
S[table-format = 4.2]@{\,}
l|
p{79mm}|
S[table-format = 6.2]|
S[table-format = 6.2]|
S[table-format = 2.2]@{\,}
>{\collectcell\unit}l<{\endcollectcell}%
}
{Pos.} & \multicolumn{2}{c|}{Menge} & {Best. Nr., \quad \quad Bezeichnung} & {Preis} & {Betrag} & \multicolumn{2}{c}{MwSt} \\
\hline 
\endhead %
\sisetup{round-precision=0} 01 & 4,00 & & \begin{minipage}[t]{78mm}{\setlength{\parskip}{.2mm}\begin{description}\item[{1564933RL}]Lorem ipsum dolor sit amet dorem ipsum dolor sit amet\end{description}\vspace{.2mm}}\end{minipage} & 66.059 & 264.236 & 19.00 & \\ \tablemidlineb
\addOrderRow{4}{1233,0}{Stk.}{1564933RL}{Lorem ipsum dolor sit amet dorem ipsum dolor sit amet}{12,599}{37.797}{19,34}%

\end{longtable}

\end{letter}
\end{document}

1 Answer 1

1

This does not directly answer your question, but provides a tabularray-based alternative that may be interesting for you. tabularray provides a built-in mechanism to change the color or odd and even horizontal lines. I also replaced \begin{minipage}[t]{78mm}{\setlength{\parskip}{.2mm}\begin{description}\item[{#4}]#5\end{description}\vspace{.2mm}}\end{minipage} which I guess was just use to get the hanging indentation in the following lines of the "Bezeichnung" column. The same effect can be achieved with >{\setlength{\hangindent}{2em}}. For this column, I also used an X column type in order to make sure the table fits into the available space. Lastly, I also adjusted teh column types of the "Menge" and "MSt" columns in order to avoid the need to split number and unit into separate columns.

With these changes in place, the required input is reduced to:

4 & 1233,0 \unit{\piece} & 1564933RL Lorem ipsum dolor sit amet dorem ipsum dolor sit amet & 12,599 & 37.797 & 19,34 \unit{\percent}\\

which I doubt, that it is any more complex as the proposed

\addOrderRow{4}{1233,0}{Stk.}{1564933RL}{Lorem ipsum dolor sit amet dorem ipsum dolor sit amet}{12,599}{37.797}{19,34}

Here is the complete and simplified MWE:

\documentclass[10pt]{scrlttr2}

\usepackage[locale=DE]{siunitx}
\sisetup{
    locale = DE,
    detect-all,
    round-mode = places, %default: none
    round-precision = 2
}
\DeclareSIUnit{\piece}{Stk.}

\usepackage{xcolor}

\usepackage{longtable}
\usepackage{tabularray}
\UseTblrLibrary{siunitx}

\usepackage{ragged2e}


\begin{document}
\begin{letter}


\begin{longtblr}[label=none]{colspec={
S[table-format = 2.0, round-precision=0]
S[table-format = 4.2, table-space-text-post=\unit{\piece}]
>{\setlength{\hangindent}{2em}}X[l]|
S[table-format = 6.2]
S[table-format = 6.2]
S[table-format = 2.2, table-space-text-post=\unit{\percent}]
},  
hline{odd} = {red}, hline{even}={gray}, hline{1} = {0pt}, hline{2} ={black}, 
vlines, 
rowhead = 1, 
leftsep=3pt, rightsep=3pt}
{{{Pos.}}} & {{{Menge}}} & {{{Best. Nr., \quad \quad Bezeichnung}}} & {{{Preis}}} & {{{Betrag}}} & MwSt \\

 01 & 4,00 & 1564933RL Lorem ipsum dolor sit amet dorem ipsum dolor sit amet & 66.059 & 264.236 & 19.00  \\ 
4 & 1233,0 \unit{\piece} & 1564933RL Lorem ipsum dolor sit amet dorem ipsum dolor sit amet & 12,599 & 37.797 & 19,34 \unit{\percent}\\
 01 & 4,00 & 1564933RL Lorem ipsum dolor sit amet dorem ipsum dolor sit amet & 66.059 & 264.236 & 19.00  \\ 
4 & 1233,0 \unit{\piece} & 1564933RL Lorem ipsum dolor sit amet dorem ipsum dolor sit amet & 12,599 & 37.797 & 19,34 \unit{\percent}\\
\end{longtblr}

\end{letter}
\end{document}

and its output:

enter image description here

2
  • Yes, this is an interesting alternative for me. In the minimal example it works fine, but in my entire document I get the error "xcolor Error: Undefined color model 'rgb:Hsb'" when I add the package \usepackage{tabularray}. Since there are still some self-defined colours in the document, I have to see if I can find the error. In any case, your answer is a very good inspiration on how to simplify the whole thing. Thank you!
    – FaTiWo
    Commented Mar 29, 2022 at 6:44
  • @FaTiWo See this link for a workaround of the above error: tex.stackexchange.com/questions/614621/…
    – L.J.R.
    Commented May 15, 2022 at 2:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .