
Estou tentando exibir valores de um arquivo csv dentro de uma tabela. Para fazer isso, estou usando a macro \csvreader
. Eu gostaria que o tabulat fosse assim:
com a toprule
, o cabeçalho das colunas, a midrule
, os valores sem linha e a bottomrule
.
Aqui está o código que fiz
\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}
Para cada linha, exibo as informações da linha csv e insiro um arquivo \\
. Com este código, obtenho o seguinte resultado
com uma linha vazia adicional. Tentei remover o \\
na frente do \bottomrule
, mas resultou no erro Misclaced \noalign. \bottomrule->\noalign
.
Como eu poderia remover essa linha extra?
Responder1
Usar a opção late after line=\\
resolve este problema:
\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}