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.
- 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?
- 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}