我正在尝试构建一个表格,该表格将根据成绩自动分配第三列。因此,第三个表格依赖于第二个表格。我希望它看起来像这样,而字母实际上不在 excel 表中。谢谢!!到目前为止,我拥有的是 latex 代码,但它不起作用。
\documentclass{article}
%Packages
\usepackage{csvsimple}
\usepackage{datatool,filecontents,tabularx,booktabs}
\begin{filecontents*}{test.csv}
name,gender,grade
Hans,m,1
Anna,f,2
Anton,m,5
Hilde,f,5
\end{filecontents*}
\begin{document}
\begin{table}
\centering
\caption{trying for assigning grade}
\csvreader[tabular=ccc,
table head= \hline Name & grade & letter \\ \hline,
late after line= \\,
table foot= \hline,
]
{test.csv}{name=\name, grade=\grade}
{
\ifnumgreater{\grade}{3}
{\name & \grade & A}
\else
{\name & \grade & C}
\fi}
\end{table}
\end{document}
答案1
问题在于条件的语法不正确。我借此机会使用 和 规则改进了表格booktabs
,caption
以便在标题和表格之间留出合适的间距:
\documentclass{article}
%Packages
\usepackage{csvsimple}
\usepackage{datatool,filecontents,tabularx,booktabs, caption}
\begin{filecontents*}{test.csv}
name,gender,grade
Hans,m,1
Anna,f,2
Anton,m,5
Hilde,f,5
\end{filecontents*}
\begin{document}
\begin{table}
\centering\setlength\extrarowheight{2pt}
\caption{trying for assigning grade}
\csvreader[tabular=ccc,
table head= \toprule Name & grade & letter \\ \midrule,
late after line= \\,
table foot= \bottomrule,
]
{test.csv}{name=\name, grade=\grade}
{
\ifnumgreater{\grade}{3}
{\name & \grade & A}
{\name & \grade & C}
}
\end{table}
\end{document}