0

I have a CSV file and I want some entries be colored and bold. for example "bezahlt" should be green and bold. "unbezahlt" should be red and bold. "offen" should be black and bold. "unklar" should be stealblue and bold.

the content of the csv file

Na,Ku,Re,Be,Da,St
 Bl,Bs,631,238.00,15.01.2022,offen
 Br,Bg,632,309.40,15.01.2022,bezahlt
 Co,Cn,633,309.40,15.01.2022,unbezahlt
 Dr,De,634,952.00,15.01.2022,unklar
\documentclass{article}
\usepackage{newtxtext,newtxmath}
\usepackage{geometry}
\geometry{
    a4paper,
    total={170mm,240mm},
    left=20mm,
    top=20mm,
}
\usepackage{csvsimple}

\begin{document} \section*{Be}

\csvreader[tabular=|l|l|l|c|r|c|c|,
table head=\hline & Na & Ku& Re & Be& Da & St\\\hline,
late after line=\\\hline]%
{Jan2022.csv}{Na=\Na,Ku=\Ku,Re=\Re,Be=\Be,Da=\Da,St=\St}%
{\thecsvrow & \Na&\Ku&\Re&\Be&\Da&\St}%




\end{document}

I dont know how to add an image to show you the output. But I hope it is clear what I want to achieve.

Thank you for your help


Picture of it looks like now

enter image description here

IH Pro
  • 141

1 Answers1

5

A possible solution with csvsimple-l3 and tabularray packages:


For Short Tables

\documentclass{article}

\usepackage{csvsimple-l3} \usepackage{xcolor} \usepackage{tabularray}

\begin{filecontents}[overwrite]{\jobname.csv} Na,Ku,Re,Be,Da,St Bl,Bs,631,238.00,15.01.2022,offen Br,Bg,632,309.40,15.01.2022,bezahlt Co,Cn,633,309.40,15.01.2022,unbezahlt Dr,De,634,952.00,15.01.2022,unklar Bl,Bs,631,238.00,15.01.2022,offen Br,Bg,632,309.40,15.01.2022,bezahlt Co,Cn,633,309.40,15.01.2022,unbezahlt Dr,De,634,952.00,15.01.2022,unklar \end{filecontents}

\begin{document}

\csvreader[ tabularray = { colspec = {|l|l|l|c|r|c|c|}, cell{2-Z}{Z} = {font=\bfseries},
}, table head = \hline & Na & Ku& Re & Be& Da & St\\hline, late after line = \\hline ]{\jobname.csv}{Na=\Na,Ku=\Ku,Re=\Re,Be=\Be,Da=\Da,St=\St}{ \thecsvrow & \Na & \Ku & \Re & \Be & \Da & \ifcsvstrcmp{\St}{offen}{\SetCell{fg=gray3}\St}{ \ifcsvstrcmp{\St}{bezahlt}{\SetCell{fg=green3}\St}{ \ifcsvstrcmp{\St}{unbezahlt}{\SetCell{fg=red3}\St}{ \ifcsvstrcmp{\St}{unklar}{\SetCell{fg=azure3}\St}{\St}
} }
} }%

\end{document}

enter image description here


For Long Tables

\documentclass{article}
\usepackage[b6paper,margin=1.5cm]{geometry}

\usepackage{csvsimple-l3} \usepackage{xcolor} \usepackage{tabularray}

\begin{filecontents}[overwrite]{\jobname.csv} Na,Ku,Re,Be,Da,St Bl,Bs,631,238.00,15.01.2022,offen Br,Bg,632,309.40,15.01.2022,bezahlt Co,Cn,633,309.40,15.01.2022,unbezahlt Dr,De,634,952.00,15.01.2022,unklar Bl,Bs,631,238.00,15.01.2022,offen Br,Bg,632,309.40,15.01.2022,bezahlt Co,Cn,633,309.40,15.01.2022,unbezahlt Dr,De,634,952.00,15.01.2022,unklar Bl,Bs,631,238.00,15.01.2022,offen Br,Bg,632,309.40,15.01.2022,bezahlt Co,Cn,633,309.40,15.01.2022,unbezahlt Dr,De,634,952.00,15.01.2022,unklar Bl,Bs,631,238.00,15.01.2022,offen Br,Bg,632,309.40,15.01.2022,bezahlt Co,Cn,633,309.40,15.01.2022,unbezahlt Dr,De,634,952.00,15.01.2022,unklar Bl,Bs,631,238.00,15.01.2022,offen Br,Bg,632,309.40,15.01.2022,bezahlt Co,Cn,633,309.40,15.01.2022,unbezahlt Dr,De,634,952.00,15.01.2022,unklar Bl,Bs,631,238.00,15.01.2022,offen Br,Bg,632,309.40,15.01.2022,bezahlt Co,Cn,633,309.40,15.01.2022,unbezahlt Dr,De,634,952.00,15.01.2022,unklar Bl,Bs,631,238.00,15.01.2022,offen Br,Bg,632,309.40,15.01.2022,bezahlt Co,Cn,633,309.40,15.01.2022,unbezahlt Dr,De,634,952.00,15.01.2022,unklar Bl,Bs,631,238.00,15.01.2022,offen Br,Bg,632,309.40,15.01.2022,bezahlt Co,Cn,633,309.40,15.01.2022,unbezahlt Dr,De,634,952.00,15.01.2022,unklar Bl,Bs,631,238.00,15.01.2022,offen Br,Bg,632,309.40,15.01.2022,bezahlt Co,Cn,633,309.40,15.01.2022,unbezahlt Dr,De,634,952.00,15.01.2022,unklar \end{filecontents}

\begin{document}

\SetTblrTemplate{head,foot}{empty}

\csvreader[ generic collected table = longtblr, generic table options = {[ %caption = {My Table Caption}, %label = {my:label}, label = none, ]{ rowhead = 1, colspec = {|l|l|l|c|r|c|c|}, cell{2-Z}{Z} = {font=\bfseries},
}}, table head = \hline & Na & Ku& Re & Be& Da & St\\hline, late after line = \\hline ]{\jobname.csv}{Na=\Na,Ku=\Ku,Re=\Re,Be=\Be,Da=\Da,St=\St}{ \thecsvrow & \Na & \Ku & \Re & \Be & \Da & \ifcsvstrcmp{\St}{offen}{\SetCell{fg=gray3}}{ \ifcsvstrcmp{\St}{bezahlt}{\SetCell{fg=green3}}{ \ifcsvstrcmp{\St}{unbezahlt}{\SetCell{fg=red3}}{ \ifcsvstrcmp{\St}{unklar}{\SetCell{fg=azure3}}{}
} }
} \St }%

\end{document}

enter image description here

L.J.R.
  • 10,932
  • Thank you very much. But this table is just an example. The real table Gas Maybe 100 Lines and this Four words will repeat it‘s Self multiple time. So is the was to fix it. So always when „bezahlt“ Mentioned it becomes green. Secondly I like the Idea That the cell geht colored, nice idea, but I meant That just the Word get colored. – IH Pro Feb 02 '22 at 06:56
  • @IHPro I haved updated my answer. – L.J.R. Feb 02 '22 at 07:43
  • thank you very much. I try it out but I don't work yet. I figure out that there is ninecolors package was missing. I fix it, but until yet there is a problem. I try to figure out what is the problem, but the only thing I can read there is "Undefined control sequence. }". Do you know where the problem could be? – IH Pro Feb 02 '22 at 08:28
  • I put a picture how it looks like now – IH Pro Feb 02 '22 at 08:42
  • @IHPro You also need to update csvsimple package. – L.J.R. Feb 02 '22 at 08:43
  • @IHPro Sorry, I am not able to view pictures on this website due to network restrictions. – L.J.R. Feb 02 '22 at 08:45
  • I am sorry for this question, but how to update? do you mean add \usepackage{csvsimple} to the Latex file. I took all .sty from here https://www.ctan.org/pkg/csvsimple. Latest version. Am I now have to search the old .sty and remove them ? – IH Pro Feb 02 '22 at 09:06
  • @IHPro It is \usepackage{csvsimple-l3}, not \usepackage{csvsimple}. – L.J.R. Feb 02 '22 at 09:15
  • 1
    @IHPro You don't need to download packages from CTAN; see https://tex.stackexchange.com/questions/55437/how-do-i-update-my-tex-distribution – L.J.R. Feb 02 '22 at 09:21
  • GreatJob, Thank you very much, I learned I lot – IH Pro Feb 02 '22 at 11:05
  • a little question, If you know. This table can become very large, so since 40 rows I get a trouble. Actually I would use here longtable. But here we use tabularray. Is a way to use tabularray and If the table become to large it put the rest of the rows on the nest page ? – IH Pro Feb 02 '22 at 11:27
  • @IHPro I have added an example for long tables. – L.J.R. Feb 02 '22 at 12:40
  • man you are sick, you find always a solution. Is there a way to remove the caption like "Table 1: My Table Caption" or "continued on next page" or write it in german. I have to show it my boss and he can not read english at all. – IH Pro Feb 02 '22 at 16:27
  • 1
    @IHPro Edited my answer for you. – L.J.R. Feb 03 '22 at 00:04
  • Thank you very much – IH Pro Feb 03 '22 at 00:34