2

I am creating tables from a CSV file by using csvsimple package. The contents of the tables are all left aligned, hence I would like to know whether it is possible to center the first row alone (and the remaining rows being aligned to the left) ?

My code is:

\documentclass{beamer}
\usepackage{csvsimple}

\begin{filecontents*}{\jobname.csv}
0.1,0.4,0.7,1.0,1.3
0.201,1.001,1.801,4.601,3.401
0.200,1.000,1.800,2.600,3.400
\end{filecontents*}

\begin{document}

\begin{frame}

\csvreader[autotabular,
%full filter=\ifcsvstrcmp{\csvcoliv}{m}{\csvfilteraccept}{\csvfilterreject}
]{\jobname.csv}{}{\csvlinetotablerow}%

\end{frame}

\end{document}

Csvsimple \csvautotabular and \csvautobooktabular with centered columns' content shows how to switch the default alignment to center for the entire table, but can this be done only for the first row?

  • Great. I've added the link to the question with egreg's answer, because that might help somebody trying to answer this one and it is easier if it is in the post rather than the comments. If I've misunderstood or you don't like it, feel free to roll back the edit. (I also changed 'raw' to 'row', which I think is what you meant.) – cfr Sep 14 '17 at 15:32
  • @CFR, your edits made the question clearer. Thank you very much for spending your valuable time on this. – Ashok Sep 14 '17 at 16:37
0

It is possible with \csviffirstrow, adding \multicolumn{1}{c|}{...} for every element of the first row.

The trick of the fake first column @{}p{0pt}@{} is necessary to avoid a ! Misplaced \omit error.

\documentclass{beamer}
\usepackage{csvsimple}

\begin{filecontents*}{\jobname.csv}
0.1,0.4,0.7,1.0,1.3
0.201,1.001,1.801,4.601,3.401
0.200,1.000,1.800,2.600,3.400
\end{filecontents*}

\begin{document}

\begin{frame}
\begin{tabular}{@{}p{0pt}@{}|*5{l|}}
    \hline
    \csvreader[
        no head,
        late after line=\\\hline,
        ]{\jobname.csv}{}{%
            \csviffirstrow{%
                & \multicolumn{1}{c|}{\csvcoli} & \multicolumn{1}{c|}{\csvcolii} & \multicolumn{1}{c|}{\csvcoliii} & \multicolumn{1}{c|}{\csvcoliv} & \multicolumn{1}{c|}{\csvcolv}
            }{%
                & \csvcoli & \csvcolii & \csvcoliii & \csvcoliv & \csvcolv
            }%
        }
\end{tabular}
\end{frame}
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.