3

I'm trying to build a table that will have a table that will automatically assign a third column depending on the grade. So, the third table is dependant on the second one. I want it to look something like this without the letter actually being in the excel sheet. Thank you!! The latex code is what I have so far, but it doesn't work.

enter image description here

\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 Answer 1

5

The problem was the incorrect syntax for the conditional. I took the opportunity to improve the table with the rules of booktabs and caption, for a decent spacing between caption and table:

\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} 

enter image description here

1
  • 'Twas a pleasure to help! Welcome to TeX SX!
    – Bernard
    May 5, 2017 at 16:04

You must log in to answer this question.

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