Latest news 2019-12-05: new blog post "RSS Feeds and Other Notifications."

Bug Tracker

ID81
StatusClosed (Not a Bug)
Categorydatatool
Version2.22
SummarySpurious line in tabular with

Report

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}%
\DTLnewdbentry{mydata}{Surname}{Adams}%


\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}


Ronan Keryell

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}%
\DTLnewdbentry{mydata}{Surname}{Adams}%


\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.

Add comment.

Watch This Report

If you would like to be notified whenever updates are made to this report, please fill in your email address in the box below and click on "Notify Me of Changes" button. (Please ensure the address is valid.) Your details won't be passed on to third parties in line with this site's Privacy Policy.

If you supply your name, it will be used in the email greeting, which provides a more personal message, otherwise you'll just get a generic greeting. If you have previously supplied your name when signing up for notifications, you don't need to resupply it unless you want to change it.

If you have previously subscribed to notifications for this report, you can unsubscribe by clicking on the "Stop Notification" button.

The "Confirm Bug ID" field helps to protect against spambots. Please enter the bug ID (which you can find at the top of this page).

(Optional.)
E mail:
Confirm E mail:
Confirm Bug ID:

To unsubscribe from all notifications use the notifications page.

Comment

You can append a comment to the report using the form below. Comments are checked first before being added. Any spam or offensive content will be removed first according to this site's Terms of Website Use. Please bear in mind that I develop and maintain free software in my spare time. If you want commerical level support then you can hire a TeX consultant.

The "Confirm Bug ID" field helps to protect against spambots. Please enter the bug ID (which you can find at the top of this page).

(Optional. If provided, it will be shown with the comment.)
Confirm Bug ID:

You can use the following markup:

[pre]Displayed verbatim[/pre]
[tt]monospace text[/tt]
[em]emphasized text[/em]
[b]bold text[/b]
[url]web address[/url]

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

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

Click on the Preview button to preview the message.

Return to list.

© 2019 Dickimaw Books. "Dickimaw", "Dickimaw Books" and the Dickimaw parrot logo are trademarks. The Dickimaw parrot was painted by Magdalene Pritchett.

Terms of Use Privacy Policy Cookies Site Map FAQs