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}
  • What about 3 --> \textcolor{red}{t3}? – Svend Tveskæg Aug 1 '13 at 9:59
  • @SvendTveskæg perhaps the OP wish is for an automated way to detect that 3 is indeed the smallest row entry? – user4686 Aug 1 '13 at 14:11
  • @jfbu Good point. (And of course t3 should be 3.) – Svend Tveskæg Aug 1 '13 at 14:16
  • Related: tex.stackexchange.com/questions/33967/… (This question is for pgfplotstable, so not a duplicate, but if you're not locked to datatool, perhaps it can be of help anyway.) – Torbjørn T. Aug 5 '13 at 8:42
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}
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.