# Alignment in first row, first column of table generated by DTLforeach

I have a simple table:

\documentclass{article}
\pagestyle{empty}
\begin{document}
\begin{table}[ht]
\centering
\begin{tabular}{c c}
\hline\hline
x & y \\ [0.5ex]
\hline
1 & 4 \\
2 & 6 \\
3 & 8 \\
[1ex]
\hline
\end{tabular}
\end{table}
\end{document}


It looks like this:

I would like to replicate this with datatool, keeping the same horizontal lines and vertical space:

\documentclass{article}
\usepackage{datatool}
\usepackage{filecontents}
\pagestyle{empty}
\begin{filecontents*}{input.csv}
x,y
1,4
2,6
3,8
\end{filecontents*}
\begin{document}
\begin{table}[ht]
\centering
\begin{tabular}{c c}
\hline\hline
x & y \\ [0.5ex]
\hline
\DTLforeach{mytable}
{\x=x,\y=y}
{
\DTLiffirstrow{}{\\}
\x & \y
}
\\
[1ex]
\hline
\end{tabular}
\end{table}
\end{document}


This is almost the same, but the 1 is misaligned horizontally:

How do I fix this?

• Avoid \pagenumbering{gobble}. If you don't want page numbers, use \pagestyle{empty}. – egreg Nov 9 '17 at 9:55
• Alright, fixed it. – Nathaniel M. Beaver Nov 9 '17 at 14:25

Spot the differences:

\begin{filecontents*}{\jobname.csv}
x,y
1,4
2,6
3,8
\end{filecontents*}

\documentclass{article}
\usepackage{datatool}

\begin{document}

\begin{table}[ht]
\centering
\begin{tabular}{c c}
\hline\hline
x & y \\ [0.5ex]
\hline
\DTLforeach{mytable}
{\x=x,\y=y}
{%
\DTLiffirstrow{}{\\}%
\x & \y
}
\\[1ex]
\hline
\end{tabular}
\end{table}
\end{document}


No, the position of filecontents and the file name are irrelevant. Look for %.

You added two spaces with the end-of-lines; the first one is not really relevant, because LaTeX will ignore it, but the one after \DTLiffirstrow{}{\\} doesn't get ignored.