1

I'm trying to display values from a csv file inside a tabular. To do so, I'm using the macro \csvreader. I would like thr tabulat to like this way :

desired result

with a toprule, the head of columns, a midrule, the values with no line and a bottomrule.

Here is the code I made

\begin{tabular}{*{4}{c}}%
    \toprule
    \textbf{Mesh} & $h$ & \textbf{nDof $\P_1$} & \textbf{nDof $\P_2$}\\
    \midrule
    \csvreader[head to column names]{fig/meshInformation3D.csv}{}
    {\texttt{\mesh} & \pgfmathprintnumber{\hAvg} & \pgfmathprintnumber{\nDofPUn} & \pgfmathprintnumber{\nDofPDeux}\\}
    \\\bottomrule
\end{tabular}

For each line, I display the information of the csv row, then I insert a \\. With this code, I get the following result

result

with an additional empty line. I tried to remove the \\ in front of the \bottomrule, but it result in the error Misclaced \noalign. \bottomrule->\noalign.

How could I remove this extra line ?

1
  • You should probably use the option late after line = \\ . See the answers to this question. Did you take a look at the manual? The manual has a lot of nice examples, including the use of \bottomrule. Mar 13, 2023 at 15:17

1 Answer 1

1

Using the option late after line=\\ solves this problem:

\documentclass{article}
\usepackage{pgf}
\usepackage{amssymb}
\usepackage{csvsimple}
\usepackage{booktabs}

\begin{filecontents}[noheader]{mylist.csv}
mesh, hAvg, nDofPUn, nDofPDeux 
M0  , 0.86, 47384  , 327000    
M1  , 0.74, 68993  , 473000    
\end{filecontents}

\begin{document}
\begin{tabular}{*{4}{c}}%
    \toprule
    \textbf{Mesh} & $h$ & \textbf{nDof $\mathbb{P}_1$} & \textbf{nDof $\mathbb{P}_2$} \\
    \midrule
    \csvreader[head to column names, late after line=\\]{mylist.csv}{}{
        \texttt{\mesh} & 
        \pgfmathprintnumber{\hAvg} & 
        \pgfmathprintnumber{\nDofPUn} & 
        \pgfmathprintnumber{\nDofPDeux}
    }
    \bottomrule
\end{tabular}
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .