Your question is quite general and such not easy to answer. But, if I understand you right, you want to use special characters in your table head and you want to read them from your csv file.
The \csvautotabular
macro is intended for quick survey only and not for productive tables, since it is quite restricted. \csvreader
or \csvloop
are indented for normal usage.
To use the first line of a csv file as normal data line, you have to say no head
and also to give column count
since this first line is not read as pattern. Then, this line can be used as data line.
Still, there is and will be an important restriction: A line is not allowed to start with a backslash \
.
Now, here comes an example:
\begin{filecontents*}{test3.csv}
Wei\ss{}b\"ack,\textbf{bold},c
2,2,8
3,6,9
\end{filecontents*}
\documentclass{letter}
\usepackage[utf8]{inputenc}
\usepackage{csvsimple}
\begin{document}
\csvloop{
file=test3.csv,
no head, % no special treatment of first line
column count=3, % since no first line is given, tell about column count
before reading=\begin{tabular}{|l|l|l|}\hline,
command=\csvlinetotablerow,
late after line=\\,
late after first line=\\\hline,
late after last line=\\\hline,
after reading=\end{tabular}
}
\end{document}
\documentclass[]{article}
% \usepackage{csvsimple} % remove this for second solution
\usepackage{datatool} % add this for second solution
\usepackage{booktabs}
\usepackage[T1]{fontenc}
% \usepackage{underscore} %<- This solves your problem % remove this for second solution
\begin{document}
\section{csvreader}
% This works
% \csvreader[%
% respect all,%
% autotabular%
% ]{test.csv}{}{\csvlinetotablerow}%
\section{datatool simple}
\DTLloadrawdb[noheader,keys={a,b,c,d},headers={a,b,c,d}]{t2g}{test.csv}
\begin{table}[htbp]
\centering
\begin{tabular}{|c|c|c|c|}\hline
\DTLdisplaydb{t2g}
\\ \hline
\end{tabular}
\end{table}
% \DTLdisplaylongdb{iris}
\section{datatool not simple}
% This does not
\begin{table}[htbp]
\centering
\begin{tabular}{|c|c|c|c|}\hline
\DTLforeach{t2g}{\ca=a, \cb=b, \cc=c,\cd=d}%
{%
\DTLiffirstrow{}%
{%
\\ \hline
}
\ca&%
\cb&%
\cc&%
\cd%
}%
\\ \hline
\end{tabular}
\end{table}
\end{document}
What about this solution?
;)
Best Answer
You can use the second mandatory argument for setting aliases for the column names: