4

I'm trying to classify laws by level (federal, state and local) and by theme (waste, sanitary sewage) and show it on a table. I wrote the follow MWE:

\documentclass{article}

\usepackage{datatool}
\usepackage{filecontents}

\begin{filecontents}{legis.csv}
level;theme;norm;number;date;subject
federal;waste;"Federal Law";12305;8/2/2010;"Institutes the National Policy on Solid Waste."
state;waste;"State Law";11107;4/6/2005;"Provides general rules for management of solid waste."
local;waste;"Local Law";7797;7/10/2017;"Creates the Green Environment Fund and makes other arrangements."
\end{filecontents}

\begin{document}

\DTLsetseparator{;}
\DTLloaddb[keys={level,theme,norm,number,date,subject}]{legis}{legis.csv}

\begin{tabular}{@{\hspace{1cm}}l}

\multicolumn{1}{l}{\bfseries Federal law}\\

\DTLforeach*[\DTLiseq{\level}{federal}\and\DTLiseq{\theme}{waste}]{legis}
{\norm=norm,\number=number,\date=date,\subject=subject}
{%
\begin{tabular}{lll}
\norm & \number & \date
\end{tabular}\\
\begin{tabular}@{\hspace{1cm}}{p{10cm}}
\subject
\end{tabular}\\
}

\multicolumn{1}{l}{\bfseries State law}\\

\DTLforeach*[\DTLiseq{\level}{state}\and\DTLiseq{\theme}{waste}]{leg}
{\norm=norm,\number=number,\date=date,\subject=subject}
{
\begin{tabular}{lll}
\norm & \number & \date
\end{tabular}\\
\begin{tabular}@{\hspace{1cm}}{p{10cm}}
\subject
\end{tabular}\\
}
\multicolumn{1}{l}{\bfseries Local law}\\

\DTLforeach*[\DTLiseq{\level}{local}\and\DTLiseq{\theme}{waste}]{leg}
{\norm=norm,\number=number,\date=date,\subject=subject}
{
\begin{tabular}{lll}
\norm & \number & \date
\end{tabular}\\
\begin{tabular}@{\hspace{1cm}}{p{10cm}}
\subject
\end{tabular}\\
}
\end{tabular}

\end{document}

but the log file always show the error: "Undefined control sequence.}" what's wrong?

1 Answer 1

3

Here is an updated version of your database table construction:

enter image description here

\documentclass{article}

\usepackage{datatool}

\begin{filecontents}[overwrite]{legis.csv}
level;theme;norm;number;date;subject
federal;waste;"Federal Law";12305;8/2/2010;"Institutes the National Policy on Solid Waste."
state;waste;"State Law";11107;4/6/2005;"Provides general rules for management of solid waste."
local;waste;"Local Law";7797;7/10/2017;"Creates the Green Environment Fund and makes other arrangements."
\end{filecontents}

\begin{document}

\DTLsetseparator{;}
\DTLloaddb[keys={level,theme,norm,number,date,subject}]{legis}{legis.csv}

\begin{tabular}{ @{\hspace{1cm}} l }
  \multicolumn{1}{l}{\bfseries Federal law} \\
  \DTLforeach*[\DTLiseq{\Level}{federal}\and\DTLiseq{\Theme}{waste}]{legis}
    {\Level=level,\Theme=theme,\Norm=norm,\Number=number,\Date=date,\Subject=subject}
    {%
      \begin{tabular}{ l l l }
        \Norm & \Number & \Date
      \end{tabular} \\
      \begin{tabular}{ @{\hspace{1cm}} p{10cm} }
        \Subject
      \end{tabular} \\
    } \\[-\normalbaselineskip]
  \multicolumn{1}{l}{\bfseries State law} \\
  \DTLforeach*[\DTLiseq{\Level}{state}\and\DTLiseq{\Theme}{waste}]{legis}
    {\Level=level,\Theme=theme,\Norm=norm,\Number=number,\Date=date,\Subject=subject}
    {%
      \begin{tabular}{ l l l }
        \Norm & \Number & \Date
      \end{tabular} \\
      \begin{tabular}{ @{\hspace{1cm}} p{10cm} }
        \Subject
      \end{tabular} \\
    } \\[-\normalbaselineskip]
  \multicolumn{1}{l}{\bfseries Local law} \\
  \DTLforeach*[\DTLiseq{\Level}{local}\and\DTLiseq{\Theme}{waste}]{legis}
    {\Level=level,\Theme=theme,\Norm=norm,\Number=number,\Date=date,\Subject=subject}
    {%
      \begin{tabular}{ l l l }
        \Norm & \Number & \Date
      \end{tabular} \\
      \begin{tabular}{ @{\hspace{1cm}} p{10cm} }
        \Subject
      \end{tabular} \\
    }
\end{tabular}

\end{document}

Some things that were problematic:

  • Using \number as a definition usage for the number field. Instead, use something like \Number (or otherwise), since \number is a TeX primitive. Similarly, \date is also a macro with a different use.

  • Your internal (inside \DLTforeach) tabular doesn't have the correct usage:

    \begin{tabular}{<col spec>}
    

    You have

    \begin{tabular}@{\hspace{1cm}}{p{10cm}}
    

    but it should be

    \begin{tabular}{ @{\hspace{1cm}} p{10cm} }
    
  • Added a closing \\ after each \DTLforeach and a vertical correction ([-\normalbaselineskip]).

  • Since the conditioning within the \DTLforeach uses \Level and \Theme, define them as well.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .