
シンプルな 2 行の csv ファイルがあり、これを csvsimple で次のように LaTeX にインポートしました。
\begin{filecontents*}{data.csv}
1,2,3,4,5
101,102,104,105,106
-1,-2,-3,-4,-5
\end{filecontents*}
...
\begin{table}
\begin{tabular}{*{5}{c}}
\csvreader{data.csv}{}{\\ \csvlinetotablerow}
\end{tabular}
\end{table}
しかし、表の左側にヘッダーを追加したいのですが、その方法がわかりません。
言い換えれば、私は次のようなものを望んでいます:
それはどうすれば実現できるのでしょうか?
答え1
2 行の csv ファイルの場合は、 を使用して行を区別できます\csviffirstrow
。最初の行と次の行の設定に 2 つのヘッダーを入力するだけです。
\documentclass[12pt]{article}
\usepackage{csvsimple}
\begin{filecontents*}{data.csv}
1,2,3,4,5
101,102,104,105,106
-1,-2,-3,-4,-5
\end{filecontents*}
\begin{document}
\begin{table}
\csvloop{
file=data.csv,
tabular=|*{6}{c|},
table head=\hline,
command=\csviffirstrow{$I_c$}{$U_\mathrm{same}$} & \csvlinetotablerow,
late after line=\\\hline,
}
\end{table}
\end{document}