Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am aware of the previous post datatool with longtable, but it didn't solve my problem.

I've a document with 10 tables or so, for each table I use this piece of code:

\DTLsetseparator{;} 
\DTLloaddb{kundt2}{kundt2.csv}
\begin{center}
\begin{longtable}{|c|c|c|}
\caption[De berekende bronsterkte van de buis]{De berekende bronsterkte van de buis} \label{tbl:kundt2} \\
\hline
\endfirsthead
\endhead
\endfoot
\endlastfoot
\DTLforeach{kundt2}{
\1=1, \2=2, \3=3}{\ifthenelse{\value{DTLrowi}>0}{
\1 & \2 & \3 \\ \hline }{}} 
\end{longtable}
\end{center}

My csv file

1;2;3;
444;555;666;
111;222;333;

etc., I know that one is fine.

Since I'm Dutch I need to use the ; sign for separating my csv values. Everything is working great even for tables longer then 4 pages but every single time there is an extra empty cell at the last row. I tried to change this line:

\DTLforeach{kundt2}{
\1=1, \2=2, \3=3}{\ifthenelse{\value{DTLrowi}>0}{
\1 & \2 & \3 \\ \hline }{}} 

to:

\DTLforeach{kundt2}{
\1=1, \2=2, \3=3}{\ifthenelse{\value{DTLrowi}>0}{
\\ \hline \1 & \2 & \3}{}} 

But then I get the extra empty cell at the first row. What am I doing wrong?

share|improve this question

1 Answer 1

datatool apparently doesn't protect its internals enough to be used in this context. You can hide the switching in \noalign as below. I also removed the center environment as it has no effect on longtable.

\documentclass{article}

\usepackage{datatool,longtable}

\begin{document}
\DTLsetseparator{;} 
\DTLloaddb{kundt2}{kundt2.csv}

\begin{longtable}{|c|c|c|}
\caption[De berekende bronsterkte van de buis]{De berekende bronsterkte van de buis} \label{tbl:kundt2} \\
\hline
\endfirsthead
\endhead
\endfoot
\endlastfoot
\noalign\bgroup
\DTLforeach{kundt2}{
\1=1, \2=2, \3=3}{\egroup\ifthenelse{\value{DTLrowi}>0}{
\1 & \2 & \3 \\ \hline }{}\noalign\bgroup}\egroup
\end{longtable}

\end{document}

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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