4

I've got a sample csv table with three columns - Pet, Names and Number. It's a list of Cats and Dogs, their respective names and the occurrence of each name. i.e.

enter image description here

The order of Cats or Dogs in the csv file is completely random so I've use latex to effectively group all of one pet into its own table in the output document.

My document creates the two tables without issues. What I would like to do is have a Checkbox and TextField in the final column, however so far have always been getting the below error when trying to do so.

! Use of \@sDTLforeach doesn't match its definition. \@ifnextchar ... \reserved@d =#1\def \reserved@a { #2}\def \reserved@b {#3}\f... l.70 ...andafter\docsvlist\expandafter{\uniquepet} ?

Document code below for reference.

Appreciate any help.


\documentclass{article}
\renewcommand{\familydefault}{\sfdefault}

\usepackage[parfill]{parskip} % Do not indent paragraphs
\usepackage{longtable, tabu}
\usepackage{datatool}
\usepackage{cellspace} 
\usepackage{makecell} 
\usepackage{booktabs}
\usepackage{hyperref}

\usepackage[a4paper,top=18mm,bottom=12mm,right=8mm,left=8mm,landscape]{geometry}

\tabulinesep=0.8mm
\setcellgapes{2pt}

\begin{filecontents*}{Pet.csv}
Pet,Name,Number
Dog,Buddy,6305
Dog,Max,5719
Dog,Molly,5402
Cat,Sadie,3389
Cat,Jake,3159
Cat,Lucy,3039
Cat,Bear,2916
Dog,Jack,2703
Dog,Shadow,2537
Dog,Abby,2467
Cat,Rocky,2455
Cat,Toby,2313
Cat,Chloe,2290
\end{filecontents*}

\begin{document}
\begin{Form}

\DTLloadrawdb{Pets}{Pet.csv}%Load vocab file

\newcommand*{\uniquepet}{}
\newcommand*{\csvlistsep}{\renewcommand{\csvlistsep}{ ,}}
\DTLforeach*{Pets}{\Pet=Pet}{%
 \expandafter\DTLifinlist\expandafter{\Pet}{\uniquepet}%
  {}% do nothing, already in list
  {% add to list
    \ifdefempty{\uniquepet}%
    {\let\uniquepet\Pet}% first element of list
    {% append to list
      \eappto\uniquepet{,\Pet}%
    }%
  }%
}


\newcommand{\nextrow}{}
\renewcommand{\nextrow}{}
\newcolumntype{Z}{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}X}
\renewcommand{\do}[1]{%

\bgroup
\def\arraystretch{1}
\makegapedcells
\begin{tabular}{c} 
{\huge\bf Popular #1 Names}\\
\end{tabular}
\egroup

\CheckBox[width=1em]{Tick Box}
\TextField{Alternative}

\bgroup
\small
\begin{longtabu} to \textwidth { @{} p{19mm} |  p{24mm} |  Z }
{\bf Name} & {\bf Occurance} & {\bf Correct?} \par Tick box or enter alternative \\
\toprule \endhead
    \DTLforeach*{Pets}{\Pet=Pet, \Name=Name, \Number=Number}
      {\ifnum\pdfstrcmp{#1}{\Pet}=0 
         \eappto\nextrow{\Name & \Number & \noexpand\CheckBox[width=1em]{\Name} \par Free Text Box  \noexpand\\} % Collect rows
      \fi}%
      \nextrow % Print table row
    \bottomrule
\end{longtabu}
\egroup

\clearpage
}

\expandafter\docsvlist\expandafter{\uniquepet}

\end{Form}
\end{document}
  • What version do you have? Your MWE works fine for me with datatool version 2.29. (Unrelated, but I recommend you change \bf to \bfseries.) – Nicola Talbot Jan 29 '18 at 21:10
  • Hi @NicolaTalbot, yes the above MWE will work fine however if you replace 'Check Box' in the table cell with \CheckBox[width=1em]{Tick Box} you'll notice you're unable to put a checkbox into the table. – JTurn Jan 31 '18 at 0:57
  • 1
    Then you need to update your MWE to demonstrate the error. Did you try \noexpand\CheckBox[width=1em]{Tick Box}? – Nicola Talbot Jan 31 '18 at 15:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.