The MWE adds blank space proportional to the maximum value of the \foreach
iteration:
Why is this and how do I eliminate this additional space?
Note:
- This problem seems similar to an earlier issue I had earlier in Text being output when none should be, but I don't know how to resolve this issue.
- I am guessing this is some sort of expansion related issue as
\dtlexpandnewvalue
is required to get the correct output from the database.
Code:
\documentclass{article}
\usepackage{pgffor}
\usepackage{datatool}
\usepackage{showframe}
\newcommand*{\InitalizeDB}[1]{%
\DTLifdbexists{#1}%
{\DTLcleardb{#1}}% DB exists, so just clear it
{\DTLnewdb{#1}}% DB does not exist, so create it
}%
\newcommand*{\AddMemberToDB}[3]{%
% #1 = name of DB
% #2 = db key to be used
% #3 = member to be added to DB
\dtlexpandnewvalue%
\DTLnewrow{#1}%
\DTLnewdbentry{#1}{#2}{#3}%
}%
\begin{document}
\InitalizeDB{MyDB}
\noindent
abc%
\foreach \x in {2,...,7} {%
\AddMemberToDB{MyDB}{MyDBKey}{\x}%
}%
def
\bigskip\noindent
Database:\par
\DTLdisplaydb{MyDB}
\end{document}