datatool with longtable
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.
So for your code specifically:
\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}
\DTLloaddb{names}{namelist.csv}
%==================================================================
\begin{document}
%
\begin{landscape}
%
\doublespacing
%
\newcolumntype{C}{>{\centering\arraybackslash}p{2em}} % THIS COMMAND ADDED
\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
\endfirsthead
%
\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
\endhead
%
\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.