I´m new to Latex and a bit overwhelmed by the difficulty of getting a table that looks just as I want from a csv.
- I got so far to display my csv table in latex with gray and white rows using this code:
\documentclass{article}
\usepackage[l3]{csvsimple}
\usepackage[table]{xcolor}
\usepackage{nicematrix}% for later
\usepackage{filecontents}
\begin{filecontents*}[overwrite]{data.csv}
Pair,Estimate,SE,df,z.ratio,p.value
Control - Decomposed,-2.868,0.434,Inf,-6.61,0.001
Control - Low kelp,-2.596,0.428,Inf,-6.065,0.001
Control - High kelp,-2.533,0.429,Inf,-5.91,0.001
Decomposed - Low kelp,0.272,0.171,Inf,1.591,0.384
Decomposed - High kelp,0.335,0.178,Inf,1.877,0.238
Low kelp - High kelp,0.063,0.171,Inf,0.366,0.983
\end{filecontents*}
\csvstyle{mystyle}{
no head,
table head = \\\rowcolor{gray!50},
late after line = \ifcsvoddrow{\\\rowcolor{gray!15}}{\\\rowcolor{white}}
}
\begin{document}
\begin{table}
\centering
\caption{Post-hoc test of GLMM\label{phoctab}}
\csvreader[tabular = lcccc, mystyle]{data.csv}{}{\csvcoli & \csvcolii & \csvcoliii & \csvcolv & \csvcolvi}
\end{table}
\end{document}
The only problem is the very tiny white spaces between columns. I tried to apply @F. Pantigny`s solution to this problem using the package nicematrix (NiceTabular).
But I can´t get csvsimple and nicematrix combined, so that the result is a table like above without the white space...
Here is what I started with:
\begin{NiceTabular}{lcccc}
\CodeBefore
\rowcolor{gray!50}{1}
\rowcolors{2}{gray!25}{white}
\Body
\csvreader[no head]{data.csv}{}{\csvcoli & \csvcolii & \csvcoliii & \csvcolv & \csvcolvi}
\end{NiceTabular}
- Doesn´t compile:
Fatal Package nicematrix Error: Too much columns.
(nicematrix) In the row 1, you try to use more columns
(nicematrix) than allowed by your environment
(nicematrix) {NiceTabular}. The maximal number of
(nicematrix) columns is 5 (plus the potential exterior
(nicematrix) ones).This error is fatal.
- This is the best I could get after 2 hours experimenting and researching:
\begin{NiceTabular}{lcccc}
\csvreader[mystyle]{data.csv}{}{\csvcoli & \csvcolii & \csvcoliii & \csvcolv & \csvcolvi}
\end{NiceTabular}
This does compile and has no white space between columns but looks quite awful.
How do I get this to work? Sorry if there is already a question like this somewhere, I really did try to find one!