突出显示 csvsimple 表中每行的最大值

突出显示 csvsimple 表中每行的最大值

我目前正在使用csvsimple(在 pdfLaTeX 中)从 csv 文件生成表格:


\documentclass{article}
\usepackage{xcolor}

\usepackage{csvsimple}
\usepackage{siunitx}
\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{float}


\begin{document}

\def\myasdf{1.5cm}
\begin{table}[htbp]
  \sisetup{round-mode=places, round-precision=4}
  \centering
  \csvreader[tabular=l|p{\myasdf}p{\myasdf}p{\myasdf}p{\myasdf}p{\myasdf}p{\myasdf},
            table head=\toprule Test Sequence & A & B & C & D & E & F\\ \midrule,
            head to column names,
            late after last line=\\\bottomrule]
            {csvs/data.csv}%
            {liu2021_vimeo90k_weighted_ex5a-v1_325000=\liuexFivea,
            liu2021_vimeo90k_weighted_ex1a-v1_825000=\liuexOnea,
            drdbnet_vimeo90k_weighted_ex16a-v1_375000=\drdbSixteena,
            drdbnet_vimeo90k_weighted_ex12b-v3_682917=\drdbTwelveb}%
            {\csvcoli & \num{\liuexFivea} & \num{\liuexOnea} &%
             \num{\drdbSixteena} & \num{\drdbTwelveb} & \num{\yadif} & \num{\zhu}
            }\\
  \caption{Example Caption}
  \label{tab:table1}
\end{table}


\end{document}

我该如何修改此代码以突出显示每行中的最大值?我不在乎是通过使文本加粗、更改单元格背景颜色还是任何其他方式。


到目前为止我发现

不过,我更愿意不必学习如何使用新包,因为我的表格已经看起来像我想要的那样,而且我知道如何调整我已有的表格以用于类似用途。有没有办法用 csvsimple 来实现这种突出显示?

答案1

一个简单的 csv 文件610711.csv

ooo,aaa,bbb,ccc,ddd,eee,fff
ooa,0.32,0.22,0.99,0.35,1.22,0.19
oob,1.22,1.72,3.27,2.05,3.21,3.27
ooc,4.10,0.32,2.49,1.10,0.52,2.19

带有代码的解决方案expl3

\documentclass{article}

\usepackage[table]{xcolor}
\usepackage{csvsimple}
\usepackage{siunitx}
\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{float}

\begin{document}

\ExplSyntaxOn
\NewDocumentCommand { \getmax } { }
  {
    \clist_gset:Nx \g_tmpa_clist {\aaa, \bbb, \ccc, \ddd, \eee, \fff}
    \clist_sort:Nn \g_tmpa_clist
      {
        \fp_compare:nNnTF {##1} < {##2}
          { \sort_return_swapped: }
          { \sort_return_same: }
      }
    \tl_gset:Nx \g_tmpa_tl { \clist_item:Nn \g_tmpa_clist {1} }
  }
\NewDocumentCommand { \mynum } { m }
  {
    \fp_compare:nNnTF { #1 } = { \g_tmpa_tl }
      { \cellcolor{blue!20} \num{#1} }
      { \num{#1} }
  }
\ExplSyntaxOff

\def\myasdf{1.5cm}
\begin{table}[htbp]
  \sisetup{round-mode=places, round-precision=4}
  \centering
  \csvreader[tabular=lp{\myasdf}p{\myasdf}p{\myasdf}p{\myasdf}p{\myasdf}p{\myasdf},
            table head=\toprule Test Sequence & A & B & C & D & E & F\\ \midrule,
            head to column names,
            before line=\getmax,
            late after last line=\\\bottomrule]
            {610711.csv}%
            {}%
            {\csvcoli & \mynum{\aaa} & \mynum{\bbb} &%
             \mynum{\ccc} & \mynum{\ddd} & \mynum{\eee} & \mynum{\fff}
            }
  \caption{Example Caption}
  \label{tab:table1}
\end{table}

\end{document}

在此处输入图片描述

相关内容