datatool 丢失一行中的第一个空格

datatool 丢失一行中的第一个空格

这是我的代码:

正如您在图像上看到的,第一个空间被挤压了;我不明白为什么。

\documentclass{article}

\usepackage{datatool}
\usepackage{colortbl}

\begin{filecontents*}{bogus_first_char.csv}
nom, prenom
A la la, toto
B lala, titi
C yoyo, tutu
\end{filecontents*}

\begin{document}

\DTLloaddb{dat}{bogus_first_char.csv}
\begin{tabular}{ll}
  nom & prenom \\
  \DTLforeach{dat}{\nom=nom, \prenom=prenom}{
  \\ \nom & \ prenom}
\end{tabular}

\end{document}

在此处输入图片描述

答案1

readarray只是为了好玩,我用/来做listofitems

\documentclass{article}

\usepackage{readarray}
\usepackage{colortbl}

\begin{filecontents*}{bogus_first_char.csv}
nom, prenom
A la la, toto
B lala, titi
C yoyo, tutu
\end{filecontents*}

\newtoks\toklist
\newcommand\addtotoklist[1]{\toklist\expandafter{\the\toklist#1}}
\newcommand\xaddtotoklist[1]{\expandafter\addtotoklist\expandafter{#1}}
\newcommand\xxaddtotoklist[1]{\expandafter\xaddtotoklist\expandafter{#1}}

\begin{document}
\readarraysepchar{@}
\readdef{bogus_first_char.csv}\myfile
This is now the contents of the macro \verb|\myfile|:\par\myfile

I parse that macro with two tiers:
\setsepchar{@/,}
\ignoreemptyitems
\readlist\mydata{\myfile}

I add the items to a token list
\toklist{\hline}
\foreachitem\x\in\mydata[]{%
  \xxaddtotoklist{\mydata[\xcnt,1]}%
  \addtotoklist{&}%
  \xxaddtotoklist{\mydata[\xcnt,2]}%
  \addtotoklist{\\\hline}%
}

and voila:

\def\tmp{\begin{tabular}{|l|l|}}
\expandafter\tmp\the\toklist
\end{tabular}
\end{document}

在此处输入图片描述

如果你的表格中不需要行分隔符,你可以将其设置为堆栈!:

\documentclass{article}
\usepackage{readarray}
\usepackage{tabstackengine}
\begin{filecontents*}{bogus_first_char.csv}
nom, prenom
A la la, toto
B lala, titi
C yoyo, tutu
\end{filecontents*}
\begin{document}
% CONVERT FILE INTO DEF
\readarraysepchar{@}
\readdef{bogus_first_char.csv}\myfile
%SET IT AS ARGUMENT TO A STACK
\def\striptail#1@\relax{#1}
\setstackEOL{@}
\setstackTAB{,}
\setstacktabulargap{2\tabcolsep}
\def\tmp{\tabularLongstack{ll}}
\expandafter\expandafter\expandafter\tmp%
\expandafter\expandafter\expandafter{\expandafter\striptail\myfile\relax}
\end{document}

在此处输入图片描述

相关内容