# datatool with longtable

I have a CSV file that has many rows. I want to typeset these rows into a table using longtable and datatool package.

1. However just before before the "lastfoot" (which says concluded) I am getting an empty row which I do not want. How to remove that extra row?
2. The columns are not equally spaced under the dates. Somebody please help me to make them equally spaced.

I am giving the sample code. The name of my CSV file is namelist.csv and it looks like this.

    number,degree,Name
1,Dr,Abdul Ali
2,Mrs,Francesca Joestar
3,Mr,Chan Ker Mei
4,Dr,Hikaru Yagami
5,Dr,Harish Kumar


My LaTeX code is below.

\documentclass[12pt]{article}
\usepackage{setspace}
\usepackage{bookman}
\usepackage{longtable}
\usepackage{pdflscape}
\usepackage[a4paper,left=1in,right=0.8in,top=0.5in,bottom=0.5in]{geometry}
\usepackage{tgschola}
\usepackage{microtype}
\usepackage{datatool}
%==================================================================
\begin{document}
%
\begin{landscape}
%
\doublespacing
%
\begin{longtable}{|l|l|c|c|r|r|r|c|c|c|c|c|c|c|c|c|c|c|}\hline
%
No.&\multicolumn{1}{c|}{Name}& \multicolumn{2}{c|}{13.12.2010}&
\multicolumn{2}{c|}{14.12.2010}&\multicolumn{2}{c|}{15.12.2010}&
\multicolumn{2}{c|}{16.12.2010}
&\multicolumn{2}{c|}{17.12.2010}&\multicolumn{2}{c|}{18.12.2010}
&\multicolumn{2}{c|}{19.12.2010} &\multicolumn{2}{c|}{20.12.2010}\\ \hline\hline
%
\multicolumn{18}{c}%
{{\bfseries  Continued from previous page}} \\
\hline
%
No.&\multicolumn{1}{c|}{Name}& \multicolumn{2}{c|}{13.12.2010}&
\multicolumn{2}{c|}{14.12.2010}&\multicolumn{2}{c|}{15.12.2010}&
\multicolumn{2}{c|}{16.12.2010}
&\multicolumn{2}{c|}{17.12.2010}&\multicolumn{2}{c|}{18.12.2010}
&\multicolumn{2}{c|}{19.12.2010} &\multicolumn{2}{c|}{20.12.2010}\\ \hline\hline
%
\hline \multicolumn{18}{|r|}{{Continued on next page}} \\ \hline
\endfoot
%
\hline
\multicolumn{18}{|r|}{{Concluded}} \\ \hline
\endlastfoot
%
\DTLforeach{names}{
\no=number, \dg=degree, \name=Name}{
\no& \dg. \name &  & &  & &  & &  &
&  &  &  &  &  &  &  & \\ \hline
}
\end{longtable}%
%
\end{landscape}
%
\end{document}


-
 I've solved your first problem, but I don't understand what you mean by the columns not being equally spaced (your second problem). Do you want the vertical lines in the date columns to be exactly halfway in each date column? – Alan Munn Jan 29 '12 at 4:42 Dear Alan Munn, Yes. That is what I want. Please give it a try. – Harish Kumar Jan 29 '12 at 6:56 Dear Alan Thank you for helping out the first problem. It works. In second one I want the vertical lines in the date columns to be exactly halfway in each date column. Please help. – Harish Kumar Jan 29 '12 at 7:03 @Dr.Harishkumar I've updated my answer. P.S. if you prefix comments with @ (e.g. @Alan) the person you are addressing the comment to will be notified. – Alan Munn Jan 29 '12 at 14:56 @AlanMunn, Thank you. I did not know this. I will follow. – Harish Kumar Jan 31 '12 at 0:59

When using \DTLforeach with \hline it's generally better to use the following schematic structure which puts the \\ and the \hline at the beginning of each non-initial row instead of at the end of each row.

\DTLforeach{<database>}{<assignments>}{%
\DTLiffirstrow{}{\\\hline}

rest of table with no final \\
}


For your second problem, there may be different solutions, but the simplest may be to use a fixed column width. If the cells will always be blank, just a p{2em} column would be fine; if you will subsequently be inserting centred text in the cells, then you need a slightly more complicated version, which is what I've use in the example.

Using the array package, I've defined a C columnn:

\newcolumntype{C}{>{\centering\arraybackslash}p{2em}}


and used this as the basis for the main c columns.

\documentclass[12pt]{article}
\usepackage{setspace}
\usepackage{longtable,array}
\usepackage{pdflscape}
\usepackage[a4paper,left=1in,right=0.8in,top=0.5in,bottom=0.5in]{geometry}
\usepackage{datatool}
%==================================================================
\begin{document}
%
\begin{landscape}
%
\doublespacing
%
\begin{longtable}{|r|l|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|} % THIS COMMAND CHANGED
\hline
%
No.&\multicolumn{1}{c|}{Name}& \multicolumn{2}{c|}{13.12.2010}&
\multicolumn{2}{c|}{14.12.2010}&\multicolumn{2}{c|}{15.12.2010}&
\multicolumn{2}{c|}{16.12.2010}
&\multicolumn{2}{c|}{17.12.2010}&\multicolumn{2}{c|}{18.12.2010}
&\multicolumn{2}{c|}{19.12.2010} &\multicolumn{2}{c|}{20.12.2010}\\ \hline\hline
%
\multicolumn{18}{c}%
{{\bfseries  Continued from previous page}} \\
\hline
%
No.&\multicolumn{1}{c|}{Name}& \multicolumn{2}{c|}{13.12.2010}&
\multicolumn{2}{c|}{14.12.2010}&\multicolumn{2}{c|}{15.12.2010}&
\multicolumn{2}{c|}{16.12.2010}
&\multicolumn{2}{c|}{17.12.2010}&\multicolumn{2}{c|}{18.12.2010}
&\multicolumn{2}{c|}{19.12.2010} &\multicolumn{2}{c|}{20.12.2010}\\ \hline\hline
%
\hline \multicolumn{18}{|r|}{{Continued on next page}} \\ \hline
\endfoot
%
\hline
\multicolumn{18}{|r|}{{Concluded}} \\ \hline
\endlastfoot
%
\DTLforeach{names}{%
\no=number, \dg=degree, \name=Name}{%
\DTLiffirstrow{}{\\\hline}  % THIS LINE HAS BEEN ADDED
\no& \dg. \name & & &  & &  & &  &
&  &  &  &  &  &  &  & % THIS LINE HAS BEEN CHANGED
}
\end{longtable}%
%
\end{landscape}
%
\end{document}


-

A blank line in LT is most likely from a spurious \\ somewhere. From your description it isn't clear if it is in the foot as an empty first row, or in the body of the table as an empty last row, these can look the same in the output, but of course are completely separate in the source.

-
 Dear sir I have included the sample code now. I could not find any spurious \\ anywhere. Please help me. – Harish Kumar Jan 29 '12 at 1:51