0

I am absolutely new to LATEX and I'm creating a table with this code:

\begin{spreadtab}{{longtable}[t t t]{lp{8.2cm}r}}
  @ \noalign{\vskip 2mm} \textbf{Position} & @ \textbf{Beschreibung} & @ \textbf{Preis in $currency$} \\ \hline
      $for(service)$ @ \noalign{\vskip 2mm} \refstepcounter{pos} \thepos 
        & @ $service.description$ 
        $if(service.details)$\newline \begin{itemize} 
          $for(service.details)$\scriptsize \item $service.details$ 
          $endfor$ \end{itemize}
          $endif$ & $service.price$\\
      $endfor$ \noalign{\vskip 10mm} \hline
  @ & @ \multicolumn{1}{r}{Subtotal:} & :={sum(c1:[0,-1])} \\
  @ & @ \multicolumn{1}{r}{MwSt. $VAT$\%:} & $VAT$/100*[0,-1] \\
  @ & @ \multicolumn{1}{r}{\textbf{Total:}} & \textbf{:={[0,-1]+[0,-2]}} \\
\end{spreadtab}

Which works fine!

I'd like to add another column and changed it to this:

\begin{spreadtab}{{longtable}[t t t t]{lp{8.2cm}r}}
  @ \noalign{\vskip 2mm} \textbf{Position} & @ \textbf{Beschreibung} & @ \textbf{Test} & @ \textbf{Preis in $currency$} \\ \hline
      $for(service)$ @ \noalign{\vskip 2mm} \refstepcounter{pos} \thepos 
        & @ $service.description$ 
        $if(service.details)$\newline \begin{itemize} 
          $for(service.details)$\scriptsize \item $service.details$ 
          $endfor$ \end{itemize}
          $endif$ & $service.price$ & $service.price$\\
      $endfor$ \noalign{\vskip 10mm} \hline
  @ & @ \multicolumn{1}{r}{Subtotal:} & :={sum(d1:[0,-1])} \\
  @ & @ \multicolumn{1}{r}{MwSt. $VAT$\%:} & $VAT$/100*[0,-1] \\
  @ & @ \multicolumn{1}{r}{\textbf{Total:}} & \textbf{:={[0,-1]+[0,-2]}} \\
\end{spreadtab} 

Which gets me this error:

! Extra alignment tab has been changed to \cr. \endtemplate

l.167 \end{spreadtab}

I know that this usually means that the number of columns do not match at each row, but in this case they do. Any idea whats wrong?

EDIT:

This is the complete tex file:

%!TEX TS-program = xelatex
%!TEX encoding = UTF-8 Unicode

\documentclass[$fontsize$, a4paper]{article}

\usepackage{pagecolor}
\usepackage{xcolor}

\definecolor{gray}{HTML}{EEEEEE}


% LAYOUT
%--------------------------------
\usepackage{geometry} 
\geometry{$geometry$}

% No page numbers
\pagenumbering{gobble}

% Left align
\usepackage[document]{ragged2e}

$if(letterhead)$
  \usepackage{wallpaper}
  \ULCornerWallPaper{1}{letterhead.pdf}
$endif$

% TYPOGRAPHY
%--------------------------------
\usepackage{fontspec} 
\usepackage{xunicode}
\usepackage{xltxtra}

% converts LaTeX specials (quotes, dashes etc.) to Unicode
\defaultfontfeatures{Mapping=tex-text}
\setsansfont{$sansfont$}

% Set paragraph break
\setlength{\parskip}{1em}

$if(sansfont)$
  \setsansfont{$sansfont$}
$endif$

% Command required by how Pandoc handles the list conversion
\providecommand{\tightlist}{%
  \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}

% Set Line Height
\renewcommand{\baselinestretch}{1.2}

% TABLE CUSTOMIZATION
%--------------------------------
\usepackage{spreadtab}
\usepackage{longtable}
\usepackage{ltablex}


\usepackage[compact]{titlesec} % For customizing title sections
\titlespacing*{\section}{0pt}{3pt}{-7pt} % Remove margin bottom from the title
\renewcommand{\arraystretch}{1.5} % Apply vertical padding to table cells
\usepackage{hhline} % For single-cell borders
\usepackage{enumitem} % For customizing lists
\setlist{nolistsep} % No whitespace around list items
\setlist[itemize]{leftmargin=0.5cm} % Reduce list left indent
\setlength{\tabcolsep}{9pt} % Larger gutter between columns


% LANGUAGE
%--------------------------------
$if(lang)$
\usepackage{polyglossia}
\setmainlanguage{$lang$}
$endif$

% PDF SETUP
%--------------------------------
\usepackage[xetex, bookmarks, colorlinks, breaklinks]{hyperref}
\hypersetup
{
  pdfauthor=$author$,
  pdfsubject=Invoice Nr. $invoice-nr$,
  pdftitle=Invoice Nr. $invoice-nr$,
  linkcolor=blue,
  citecolor=blue,
  filecolor=black,
  urlcolor=blue
}

% To display custom date
% \usepackage[nodayofweek]{datetime}
% \newdate{date}{01}{12}{1867}
% \date{\displaydate{date}}
% Use this instead of \today: % \displaydate{date}


% DOCUMENT
%--------------------------------
\begin{document}
% \pagecolor{gray}

% From Address
\normalsize \sffamily \scriptsize
$for(from)$
$from$ 
$endfor$

% To Address
\normalsize \sffamily
$for(to)$
$to$\\
$endfor$

\vspace{6em}

\begin{flushright}
  \small
  $city$, \today
\end{flushright}

\vspace{1em}

% Subject
\section*{\sffamily \textsc{Angebot}}

\vspace{1em}

% Offer Details
{Angebot-Nr.:} \hspace{5.2mm} {$invoice-nr$}\\
{Ort, Datum:} \hspace{7mm} {$city$,} \today

\vspace{3em}

% Opening Note
$openingnote$

% Page Break
% \newpage

\footnotesize
\newcounter{pos}
\setcounter{pos}{0}
\STautoround*{2} % Get spreadtab to always display the decimal part
\STsetdecimalsep{,} % Use comma as decimal separator

% \begin{spreadtab}{{longtable}[t t t]{lp{8.2cm}r}}
%   @ \noalign{\vskip 2mm} \textbf{Position} & @ \textbf{Beschreibung} & @ \textbf{Preis in $currency$} \\ \hline
%       $for(service)$ @ \noalign{\vskip 2mm} \refstepcounter{pos} \thepos 
%         & @ $service.description$ 
%         $if(service.details)$ \newline \begin{itemize} 
%           $for(service.details)$\scriptsize \item $service.details$ 
%           $endfor$ \end{itemize}
%           $endif$ & $service.price$\\
%       $endfor$\noalign{\vskip 10mm} \hline
%   @ & @ \multicolumn{1}{r}{Zwischensumme:} & :={sum(c1:[0,-1])} \\
%   @ & @ \multicolumn{1}{r}{MwSt. $VAT$\%:} & $VAT$/100*[0,-1] \\
%   @ & @ \multicolumn{1}{r}{\textbf{Gesamt:}} & \textbf{:={[0,-1]+[0,-2]}} \\
% \end{spreadtab}

\begin{spreadtab}{{longtable}[t t t t]{lp{8.2cm}r}}
  @ \noalign{\vskip 2mm} \textbf{Position} & @ \textbf{Beschreibung} & @ \textbf{Test} & @ \textbf{Preis in $currency$} \\ \hline
      $for(service)$ @ \noalign{\vskip 2mm} \refstepcounter{pos} \thepos 
        & @ $service.description$ 
        $if(service.details)$\newline \begin{itemize} 
          $for(service.details)$\scriptsize \item $service.details$ 
          $endfor$ \end{itemize}
          $endif$ & $service.price$ & $service.price$\\
      $endfor$ \noalign{\vskip 10mm} \hline
  @ & @ \multicolumn{1}{r}{Subtotal:} & :={sum(d1:[0,-1])} \\
  @ & @ \multicolumn{1}{r}{MwSt. $VAT$\%:} & $VAT$/100*[0,-1] \\
  @ & @ \multicolumn{1}{r}{\textbf{Total:}} & \textbf{:={[0,-1]+[0,-2]}} \\
\end{spreadtab} 

\vspace{3em}

% Legal Note
$legalnote$

\vspace{3em}

% Closing Note
$closingnote$

\vspace{1em}

% Signature
\includegraphics[height=2.5\baselineskip]{signature.pdf} \par

$author$

% \medskip

% $author$

\end{document}

migrated from stackoverflow.com Jan 6 '17 at 1:42

This question came from our site for professional and enthusiast programmers.

  • Could you please add a complete MWE starting with \documentlcass and ending in \end{document} as well as any needed additional files? Please help us to help you. – Jan Jan 6 '17 at 9:48
  • @Jan I just did. The whole thing is a modification of this: github.com/mrzool/invoice-boilerplate – Sebastian Jan 6 '17 at 10:20
  • 2
    Why using $ within \geometry{$geometry$}? – Salim Bou Jan 10 '17 at 16:24
  • 6
    This is not a compilable example; we don't have access to your variables. – egreg Jan 10 '17 at 16:31
  • 1
    The W in MWE stands for Working and means the code sample can be copied-and-pasted and directly compiled (see: I've just been asked to write a minimal example, what is that?). With your example this is not the case. Things like \geometry{$geometry$} raise errors when using xelatex for the code sample. We need additional preprocessing with unknown variables. Please show the output of that preprocessing instead. – Schweinebacke Jan 12 '17 at 7:21
4
+50

We don't know you processing queue and the variables, e.g., $\fontsize$. So the code above is not a working example (try xelatex … for the file and you will see our problem). Nevertheless it seems you did not understand the optional and mandatory argument of longtable.

The optional argument, [t t t] or [t t t t] in your example is a horizontal alignment parameter of the whole table not the columns. t is unknown there and so are sequences of t and will result in default alignment of the table. See the longtable manual about the valid alignment options l, r and c.

The mandatory argument, {lp{8.2cm}r} is the column declaration. l is a left aligned column without line break, p{8.2cm} is a \parbox-column of width 8.2cm, and r is a right aligned column without line break. See an introduction to LaTeX for more information about column declaration.

So, to add one more column, you have to extend the column declaration not the already wrongly used optional horizontal alignment parameter of the whole table. For example, you may reduce the with of the p-column and should add another r-column:

\begin{spreadtab}{{longtable}{lp{8.2cm}rr}}
  @ \noalign{\vskip 2mm} \textbf{Position} & @ \textbf{Beschreibung} & @ \textbf{Test} & @ \textbf{Preis in $currency$} \\ \hline
      $for(service)$ @ \noalign{\vskip 2mm} \refstepcounter{pos} \thepos 
        & @ $service.description$ 
        $if(service.details)$\newline \begin{itemize} 
          $for(service.details)$\scriptsize \item $service.details$ 
          $endfor$ \end{itemize}
          $endif$ & $service.price$ & $service.price$\\
      $endfor$ \noalign{\vskip 10mm} \hline
  @ & @ \multicolumn{1}{r}{Subtotal:} & :={sum(d1:[0,-1])} \\
  @ & @ \multicolumn{1}{r}{MwSt. $VAT$\%:} & $VAT$/100*[0,-1] \\
  @ & @ \multicolumn{1}{r}{\textbf{Total:}} & \textbf{:={[0,-1]+[0,-2]}} \\
\end{spreadtab} 

I can only imagine that this change in the first line would solve your issue, because I cannot test it.

3

Your question was not properly formulated. It was a puzzle to figure out that you were using pandoc to generate the pdf, that the "complete code" you provided is indeed a template for pandoc (which includes even a mini-language to create loops, like in $for(service)$, etc. That the values of all those $variables have to be provided in an external YAML file, etc.

The link you gave in a comment to https://github.com/mrzool/invoice-boilerplate provided the missing piece of the puzzle, which allowed me to generate a truly "Minimal Working Example" from your template (well, not really "Minimal" and certainly not "Working", but you get the idea).

After some tweaking I finally got the expected (I hope!) result:

Result

To get finally there, I had to do the following:

  1. Create a file called template.tex with the code you provided in the question.
  2. Create a file called details.yml copied from https://github.com/mrzool/invoice-boilerplate/blob/master/details.yml, and change the line sansfont: Helvetica Neue by sansfont: "Nimbus Sans L", since I didn't had Helvetica Neue in my system.
  3. Comment out your line \includegraphics[height=2.5\baselineskip]{signature.pdf} \par, since I didn't have the file signature.pdf.
  4. Create the .tex file with pandoc details.yml -o output.tex --template=template.tex
  5. Compile the result with xelatex output.tex, to get the final pdf shown above.

After all of this, I finally had a "Minimal non-Working Example" showing the problem you described in your question. Note all the information I had to guess to get here, and you'll understand why I started with "Your question was not properly formulated".

After this, the solution was trivial, and it was indeed the one guessed by Schweinebacke, i.e., adding a second r after lp{8.2cm}r, for the reasons explanied by Schweinebacke.

Just for reference, this is the .tex generated by pandoc, which produces the image shown above when compiled with xelatex:

%!TEX TS-program = xelatex
%!TEX encoding = UTF-8 Unicode

\documentclass[10pt, a4paper]{article}

\usepackage{pagecolor}
\usepackage{xcolor}

\definecolor{gray}{HTML}{EEEEEE}


% LAYOUT
%--------------------------------
\usepackage{geometry} 
\geometry{a4paper, left=43mm, right=43mm, top=51mm, bottom=17mm}

% No page numbers
\pagenumbering{gobble}

% Left align
\usepackage[document]{ragged2e}


% TYPOGRAPHY
%--------------------------------
\usepackage{fontspec} 
\usepackage{xunicode}
\usepackage{xltxtra}

% converts LaTeX specials (quotes, dashes etc.) to Unicode
\defaultfontfeatures{Mapping=tex-text}
\setsansfont{Nimbus Sans L}

% Set paragraph break
\setlength{\parskip}{1em}

  \setsansfont{Nimbus Sans L}

% Command required by how Pandoc handles the list conversion
\providecommand{\tightlist}{%
  \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}

% Set Line Height
\renewcommand{\baselinestretch}{1.2}

% TABLE CUSTOMIZATION
%--------------------------------
\usepackage{spreadtab}
\usepackage{longtable}
\usepackage{ltablex}


\usepackage[compact]{titlesec} % For customizing title sections
\titlespacing*{\section}{0pt}{3pt}{-7pt} % Remove margin bottom from the title
\renewcommand{\arraystretch}{1.5} % Apply vertical padding to table cells
\usepackage{hhline} % For single-cell borders
\usepackage{enumitem} % For customizing lists
\setlist{nolistsep} % No whitespace around list items
\setlist[itemize]{leftmargin=0.5cm} % Reduce list left indent
\setlength{\tabcolsep}{9pt} % Larger gutter between columns


% LANGUAGE
%--------------------------------
\usepackage{polyglossia}
\setmainlanguage{english}

% PDF SETUP
%--------------------------------
\usepackage[xetex, bookmarks, colorlinks, breaklinks]{hyperref}
\hypersetup
{
  pdfauthor=Max Mustermann,
  pdfsubject=Invoice Nr. 2015-11-04,
  pdftitle=Invoice Nr. 2015-11-04,
  linkcolor=blue,
  citecolor=blue,
  filecolor=black,
  urlcolor=blue
}

% To display custom date
% \usepackage[nodayofweek]{datetime}
% \newdate{date}{01}{12}{1867}
% \date{\displaydate{date}}
% Use this instead of \today: % \displaydate{date}


% DOCUMENT
%--------------------------------
\begin{document}
% \pagecolor{gray}

% From Address
\normalsize \sffamily \scriptsize
Musterstraße 37 
12345 Musterstadt 

% To Address
\normalsize \sffamily
Erika Mustermann\\
Musterallee 1\\
12345 Musterstadt\\
Germany\\

\vspace{6em}

\begin{flushright}
  \small
  Musterstadt, \today
\end{flushright}

\vspace{1em}

% Subject
\section*{\sffamily \textsc{Angebot}}

\vspace{1em}

% Offer Details
{Angebot-Nr.:} \hspace{5.2mm} {2015-11-04}\\
{Ort, Datum:} \hspace{7mm} {Musterstadt,} \today

\vspace{3em}

% Opening Note


% Page Break
% \newpage

\footnotesize
\newcounter{pos}
\setcounter{pos}{0}
\STautoround*{2} % Get spreadtab to always display the decimal part
\STsetdecimalsep{,} % Use comma as decimal separator

% \begin{spreadtab}{{longtable}[t t t]{lp{8.2cm}r}}
%   @ \noalign{\vskip 2mm} \textbf{Position} & @ \textbf{Beschreibung} & @ \textbf{Preis in EUR} \\ \hline
%        @ \noalign{\vskip 2mm} \refstepcounter{pos} \thepos 
%         & @ The first service provided 
%          & 320.0\\
%        @ \noalign{\vskip 2mm} \refstepcounter{pos} \thepos 
%         & @ And another one, with a list of details 
%          \newline \begin{itemize} 
%           \scriptsize \item Some more detailed explanation 
%           \scriptsize \item of the service provided 
%           \scriptsize \item Looking good 
%            \end{itemize}
%            & 245.0\\
%        @ \noalign{\vskip 2mm} \refstepcounter{pos} \thepos 
%         & @ The last service provided 
%          & 65.0\\
%       \noalign{\vskip 10mm} \hline
%   @ & @ \multicolumn{1}{r}{Zwischensumme:} & :={sum(c1:[0,-1])} \\
%   @ & @ \multicolumn{1}{r}{MwSt. 20\%:} & 20/100*[0,-1] \\
%   @ & @ \multicolumn{1}{r}{\textbf{Gesamt:}} & \textbf{:={[0,-1]+[0,-2]}} \\
% \end{spreadtab}

\begin{spreadtab}{{longtable}[t t t]{lp{8.2cm}rr}}
  @ \noalign{\vskip 2mm} \textbf{Position} & @ \textbf{Beschreibung} & @ \textbf{Test} & @ \textbf{Preis in EUR} \\ \hline
       @ \noalign{\vskip 2mm} \refstepcounter{pos} \thepos 
        & @ The first service provided 
         & 320.0 & 320.0\\
       @ \noalign{\vskip 2mm} \refstepcounter{pos} \thepos 
        & @ And another one, with a list of details 
        \newline \begin{itemize} 
          \scriptsize \item Some more detailed explanation 
          \scriptsize \item of the service provided 
          \scriptsize \item Looking good 
           \end{itemize}
           & 245.0 & 245.0\\
       @ \noalign{\vskip 2mm} \refstepcounter{pos} \thepos 
        & @ The last service provided 
         & 65.0 & 65.0\\
       \noalign{\vskip 10mm} \hline
  @ & @ \multicolumn{1}{r}{Subtotal:} & :={sum(d1:[0,-1])} \\
  @ & @ \multicolumn{1}{r}{MwSt. 20\%:} & 20/100*[0,-1] \\
  @ & @ \multicolumn{1}{r}{\textbf{Total:}} & \textbf{:={[0,-1]+[0,-2]}} \\
\end{spreadtab} 

\vspace{3em}

% Legal Note


\vspace{3em}

% Closing Note
Please transfer the due amount to the following bank account within the
next 14 days:

Mustermann GmbH\\
Kreditinstitut: Deutsche Postbank AG\\
IBAN: DE18 3601 0043 9999 9999 99\\
BIC: PBNKDEFF\\
We really appreciate your business and look forward to future projects
together. Best regards,

\vspace{1em}

% Signature
%\includegraphics[height=2.5\baselineskip]{signature.pdf} \par

Max Mustermann

% \medskip

% Max Mustermann

\end{document}

I don't understad why you didn't accept his answer, and istead offered a bounty. Did you try the solution proposed by him? Anyway, I think Schweinebacke deserves the bounty hence he gave the right answer.

  • Nice analyzation of the working process. – Schweinebacke Jan 12 '17 at 10:33

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.