# Bug Tracker

One or more errors has occurred:
• Invalid search_category value

ID 81🔗 2015-04-03 22:42:25 Closed (Not a Bug) datatool 2.22 Spurious line in tabular with

## Description

Hello!
Thank you for the amazing datatool!

I have an issue with a spurious line appearing in a tabular environment.

I spent hours on datatool.sty with \tracingall and \tracingmacro=1 tracking some spurious active space or cr but did not find anything...

So I wrote this bug report with a simple example to exhibit the issue. Actually I found no sample in the documentation with a \hline at the end that would have shown this bug...

Thank you!

\documentclass{report}
\usepackage{datatool}
\begin{document}

\DTLnewdb{mydata}
\DTLnewrow{mydata}%
\DTLnewdbentry{mydata}{FirstName}{John}%
\DTLnewdbentry{mydata}{Surname}{Smith, Jr}%
\DTLnewdbentry{mydata}{Score}{68}%
\DTLnewrow{mydata}%
\DTLnewdbentry{mydata}{FirstName}{Jane}%
\DTLnewdbentry{mydata}{Surname}{Brown}%
\DTLnewdbentry{mydata}{Score}{75}%
\DTLnewrow{mydata}%
\DTLnewdbentry{mydata}{FirstName}{Andy}%
\DTLnewdbentry{mydata}{Surname}{Brown}%
\DTLnewdbentry{mydata}{Score}{42}%
\DTLnewrow{mydata}%
\DTLnewdbentry{mydata}{FirstName}{Z\"oe}%
\DTLnewdbentry{mydata}{Score}{52}%

\DTLdisplaydb{mydata}

There is a spurious tabular line at the end:\\
\begin{tabular}{|l|l|r|}%
\hline%
\DTLforeach{mydata}{%
\firstname=FirstName,\surname=Surname,\score=Score}{%
\firstname & \surname & \score\\\hline}%
\end{tabular}

In a manual tabular, no spurious line at the end:\\
\begin{tabular}{|l|l|r|}
\hline
A & B & C\\\hline
C & D & E\\\hline
\end{tabular}

\end{document}



## MWE

\documentclass{report}
\usepackage{datatool}
\begin{document}

\DTLnewdb{mydata}
\DTLnewrow{mydata}%
\DTLnewdbentry{mydata}{FirstName}{John}%
\DTLnewdbentry{mydata}{Surname}{Smith, Jr}%
\DTLnewdbentry{mydata}{Score}{68}%
\DTLnewrow{mydata}%
\DTLnewdbentry{mydata}{FirstName}{Jane}%
\DTLnewdbentry{mydata}{Surname}{Brown}%
\DTLnewdbentry{mydata}{Score}{75}%
\DTLnewrow{mydata}%
\DTLnewdbentry{mydata}{FirstName}{Andy}%
\DTLnewdbentry{mydata}{Surname}{Brown}%
\DTLnewdbentry{mydata}{Score}{42}%
\DTLnewrow{mydata}%
\DTLnewdbentry{mydata}{FirstName}{Z\"oe}%
\DTLnewdbentry{mydata}{Score}{52}%

\DTLdisplaydb{mydata}

There is a spurious tabular line at the end:\\
\begin{tabular}{|l|l|r|}%
\hline%
\DTLforeach{mydata}{%
\firstname=FirstName,\surname=Surname,\score=Score}{%
\firstname & \surname & \score\\\hline}%
\end{tabular}

In a manual tabular, no spurious line at the end:\\
\begin{tabular}{|l|l|r|}
\hline
A & B & C\\\hline
C & D & E\\\hline
\end{tabular}

\end{document}



## Evaluation

This is unfortunately a feature rather than a bug and is why all the examples in the manual place \\ at the start of the final argument of \DTLforeach. This is due to additional stuff that has to be performed at the end of each iteration (such as incrementing the row counter) and this causes LaTeX to think a new row has started in the tabular.

This can be illustrated with a slight modification to your manual tabular:

\begin{tabular}{|l|l|r|}
\hline
A & B & C\\\hline
C & D & E\\\hline\def\tmp{stuff}%
\end{tabular}

This also adds an unwanted row.

There's no way to fix this as the commands at the end of each iteration have to come after the supplied code has been performed. The only way around this is to move the \\\hline to the start of the body. For example:

\begin{tabular}{|l|l|r|}%
\hline%
\DTLforeach{mydata}{%
\firstname=FirstName,\surname=Surname,\score=Score}{%
\DTLiffirstrow{}{\\\hline}\firstname & \surname & \score}%
\\\hline
\end{tabular}

I will have to close this as not a bug, but I will emphasis this feature in the manual.

Name (optional):

Are you human? Please confirm the bug report ID (which can be found at the top of this page) or login if you have an account.

Comment:

You can use the following markup:

Block:

[pre]Displayed verbatim[/pre]
[quote]block quote[/quote]

In line:

[tt]code[/tt]
[file]file/package/class name[/file]
[em]emphasized text[/em]
[b]bold text[/b]
[url]web address[/url] [sup]superscript[/sup]
[sub]subscript[/sub]

Ordered list:
[ol]
[li]first item[/li]
[li]second item[/li]
[/ol]

Unordered list:
[ul]
[li]first item[/li]
[li]second item[/li]
[/ul]

You can use the Preview button to review your message formatting before submitting.