
csv 파일의 값을 표 형식으로 표시하려고 합니다. 이를 위해 매크로를 사용하고 있습니다 \csvreader
. 나는 tabulat이 이런 식으로 좋아하기를 바랍니다 :
a toprule
, 열 머리, a midrule
, 줄이 없는 값 및 a bottomrule
.
내가 만든 코드는 다음과 같습니다.
\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}
각 줄에 대해 csv 행의 정보를 표시한 다음 \\
. 이 코드를 사용하면 다음과 같은 결과를 얻습니다.
추가 빈 줄이 있습니다. \\
앞에 있는 을 제거하려고 했지만 \bottomrule
오류가 발생했습니다 Misclaced \noalign. \bottomrule->\noalign
.
이 추가 줄을 어떻게 제거할 수 있습니까?
답변1
옵션을 사용하면 late after line=\\
이 문제가 해결됩니다.
\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}