
O MWE adiciona espaço em branco proporcional ao valor máximo da \foreach
iteração:
Por que isso acontece e como elimino esse espaço adicional?
Observação:
- Este problema parece semelhante a um problema anterior que tive anteriormente emTexto sendo produzido quando nenhum deveria ser, mas não sei como resolver esse problema.
- Suponho que seja algum tipo de problema relacionado à expansão,
\dtlexpandnewvalue
necessário para obter a saída correta do banco de dados.
Código:
\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}
Responder1
A macro \@dtl@updatekeys
define \@defl@dogetprops
via an \edef
e não insere %
no final da linha, causando o salto indesejado:
\newcommand*{\@dtl@updatekeys}[3]{%
\@sDTLifhaskey{#1}{#2}%
{%
\expandafter\dtlcolumnnum\expandafter
=\dtlcolumnindex{#1}{#2}\relax
\edef\@dtl@dogetprops{\noexpand\@dtl@getprops
{\noexpand\@dtl@key}{\noexpand\@dtl@type}%
{\noexpand\@dtl@colhead}{\noexpand\@dtl@before}%
{\noexpand\@dtl@after}{\the\csname dtlkeys@#1\endcsname}%
{\number\dtlcolumnnum}}% <--------- inserted '%'
\@dtl@dogetprops
%...
}
Como \@dtl@updatekeys
é muito grande, emitir \unskip
depois de adicionar um membro (parte \AddMemberToDB
ou dentro do \foreach
) resolve o problema.
\documentclass{article}
\usepackage{pgffor}% http://ctan.org/pkg/pgf
\usepackage{datatool}% http://ctan.org/pkg/datatool
\usepackage{showframe}% http://ctan.org/pkg/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}\unskip%
}%
def
\bigskip\noindent
Database:\par
\DTLdisplaydb{MyDB}
\end{document}