我正在尝试按级别(联邦、州和地方)和主题(废物、卫生污水)对法律进行分类,并将其显示在表格中。我写了以下 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}
但是日志文件总是显示错误:“未定义的控制序列。”怎么了?
答案1
以下是数据库表构造的更新版本:
\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}
存在一些问题:
使用
\number
作为字段的定义用法number
。相反,使用类似\Number
(或其他)的内容,因为\number
是 TeX 基元。类似地,\date
也是具有不同用途的宏。您的内部(内部
\DLTforeach
)tabular
没有正确的用法:\begin{tabular}{<col spec>}
你有
\begin{tabular}@{\hspace{1cm}}{p{10cm}}
但它应该是
\begin{tabular}{ @{\hspace{1cm}} p{10cm} }
\\
在每个之后添加了一个结束符\DTLforeach
和一个垂直校正([-\normalbaselineskip]
)。\DTLforeach
由于用途\Level
和内的条件\Theme
,也对它们进行定义。