![datatool 丢失一行中的第一个空格](https://linux22.com/image/373425/datatool%20%E4%B8%A2%E5%A4%B1%E4%B8%80%E8%A1%8C%E4%B8%AD%E7%9A%84%E7%AC%AC%E4%B8%80%E4%B8%AA%E7%A9%BA%E6%A0%BC.png)
这是我的代码:
正如您在图像上看到的,第一个空间被挤压了;我不明白为什么。
\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}