2

I would like to highlight the smallest number in each row. How would I go about doing this. In the following for example, would like to highlight 3 and 3.

\documentclass{article}
\usepackage{datatool}

\begin{filecontents*}{test2.csv}
    Fruits, Adam, steve
    apples, 17, 3
    oranges, 3, 18 
\end{filecontents*}

\DTLloaddb{mydata2}{test2.csv}

\begin{document}

\begin{tabular}{ll}
\bfseries Adam & \bfseries Steve & \bfseries Fruits%
\DTLforeach{mydata2}{\Adam=Adam,\Steve=Steve, \Fruits=Fruits}%
{%
\\\Fruits & \Adam & \Steve
}%
\end{tabular}

\end{document}
sachinruk
  • 427

1 Answers1

3

Since you only have two numerical columns, you can do something like:

\documentclass{article}

\usepackage{xcolor}
\usepackage{datatool}

\begin{filecontents*}{test2.csv}
    Fruits, Adam, Steve
    apples, 17, 3
    oranges, 3, 18
\end{filecontents*}

\DTLloaddb{mydata2}{test2.csv}

\begin{document}

\begin{tabular}{lll}
\bfseries Fruits & \bfseries Adam & \bfseries Steve%
\DTLforeach{mydata2}{\Adam=Adam,\Steve=Steve, \Fruits=Fruits}%
{%
\\\Fruits &
  \dtlifnumlt{\Adam}{\Steve}{\color{red}}{}\Adam &
  \dtlifnumlt{\Steve}{\Adam}{\color{red}}{}\Steve
}%
\end{tabular}

\end{document}

This produces:

Image of resulting table

If you have more than two numerical columns you can use \DTLgminall to compute the minimum for the row, like this:

\documentclass{article}

\usepackage{xcolor}
\usepackage{datatool}

\begin{filecontents*}{test2.csv}
    Fruits, Adam, Steve
    apples, 17, 3
    oranges, 3, 18
\end{filecontents*}

\DTLloaddb{mydata2}{test2.csv}

\begin{document}

\begin{tabular}{lll}
\bfseries Fruits & \bfseries Adam & \bfseries Steve%
\DTLforeach{mydata2}{\Adam=Adam,\Steve=Steve, \Fruits=Fruits}%
{%
\\\Fruits &
  \DTLgminall{\rowmin}{\Adam,\Steve}%
  \dtlifnumeq{\Adam}{\rowmin}{\color{red}}{}\Adam &
  \dtlifnumeq{\Steve}{\rowmin}{\color{red}}{}\Steve
}%
\end{tabular}

\end{document}
Nicola Talbot
  • 41,153