\foreach 내의 데이터베이스에 멤버를 추가할 때 허위 공백이 발생함

\foreach 내의 데이터베이스에 멤버를 추가할 때 허위 공백이 발생함

MWE는 \foreach반복의 최대값에 비례하여 공백을 추가합니다.

여기에 이미지 설명을 입력하세요

이유는 무엇이며 이 추가 공간을 제거하려면 어떻게 해야 합니까?

메모:

  • 이 문제는 제가 이전에 겪었던 이전 문제와 유사한 것 같습니다.아무것도 출력되지 않아야 할 때 출력되는 텍스트, 하지만 이 문제를 해결하는 방법을 모르겠습니다.
  • \dtlexpandnewvalue나는 이것이 데이터베이스에서 올바른 출력을 얻는 데 필요한 일종의 확장 관련 문제라고 생각합니다 .

암호:

\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}

답변1

매크로는 an을 통해 \@dtl@updatekeys정의 하고 줄 끝에 삽입하지 않아 원치 않는 건너뛰기를 유발합니다.\@defl@dogetprops\edef%

\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
    %...
}

\@dtl@updatekeys은 상당히 크기 때문에 \unskip멤버( 의 일부 \AddMemberToDB또는 내부 \foreach)를 추가한 후 실행하면 문제가 해결됩니다.

여기에 이미지 설명을 입력하세요

\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}

관련 정보