# Modify existing csv simple solution. Only 1st column left-aligned

Can anybody help me modify the code below, from this post in order to have only the first column as left-aligned?

Thank you.

\documentclass[11pt,a4paper,oldfontcommands]{memoir}

\usepackage{csvsimple} % For csv importing.

\makeatletter
\csvset{
autotabularcenter/.style={
file=#1,
late after line=\\,
table foot=\\\hline,
late after last line=\csv@tablefoot\end{tabular}\csv@posttable,
command=\csvlinetotablerow},
autobooktabularcenter/.style={
file=#1,
late after line=\\,
table foot=\\\bottomrule,
late after last line=\csv@tablefoot\end{tabular}\csv@posttable,
command=\csvlinetotablerow},
}
\makeatother
\newcommand{\csvautotabularcenter}[2][]{\csvloop{autotabularcenter={#2},#1}}
\newcommand{\csvautobooktabularcenter}[2][]{\csvloop{autobooktabularcenter=    {#2},#1}}

% csv file from another question
\begin{filecontents*}{\jobname.csv}
Maier,Hans,12345,m,1.0
Huber,Anna,23456,f,2.3
Weisbaeck,Werner,34567,m,5.0
\end{filecontents*}

\begin{document}

\csvautotabularcenter{\jobname.csv}

\bigskip

\csvautobooktabularcenter{\jobname.csv}

\end{document}

• Replace after head=\csv@pretable\begin{tabular}{|*{\csv@columncount} {c|}}\csv@tablehead, by after head=\csv@pretable\begin{tabular}{|l|*{\csv@columncount} {c|}}\csv@tablehead, do the job, but I'm not sure it's correct to declare one more column in the tabular environment as there is in the datafile. – Jérôme Dequeker Sep 27 '16 at 12:28

As I said as a comment, you have to redefine your tabular header.

\begin{tabular}{|*{\csv@columncount}{c}} will make a table where the number of columns has been determined from your csv file, and all the columns are centered. If you follow my comment, I suggested to add the first column as a left aligned one : \begin{tabular}{|l|*{\csv@columncount}{c}} but now, you have one more declared column in your header than in your csv file. That's why you have to add a new counter wich s equal to the number of columns minus 1, which correspond to the other centered columns :

\usepackage{etoolbox} % In the preambule
\newcommand\docolumncount[2]{%
\csvloop{
file=#1,
command=,
}%
}


So, here is my MWE :

\documentclass[11pt,a4paper,oldfontcommands]{memoir}
\usepackage{babel}
\usepackage{csvsimple} % For csv importing.
\usepackage{etoolbox}
\makeatletter
\newcommand\docolumncount[2]{%
\csvloop{
file=#1,
command=,
}%
}
\csvset{
autotabularcenter/.style={
file=#1,
late after line=\\,
table foot=\\\hline,
late after last line=\csv@tablefoot\end{tabular}\csv@posttable,
command=\csvlinetotablerow},
autobooktabularcenter/.style={
file=#1,
late after line=\\,
table foot=\\\bottomrule,
late after last line=\csv@tablefoot\end{tabular}\csv@posttable,
command=\csvlinetotablerow},
}
\makeatother
\newcommand{\csvautotabularcenter}[2][]{\csvloop{autotabularcenter={#2},#1}}
\newcommand{\csvautobooktabularcenter}[2][]{\csvloop{autobooktabularcenter={#2},#1}}

% csv file from another question
\begin{filecontents*}{\jobname.csv}
Maier,Hans,12345,m,1.0
Huber,Anna,23456,f,2.3
Weisbaeck,Werner,34567,m,5.0
\end{filecontents*}

\begin{document}
\docolumncount{\jobname.csv}{\mycolumncount}

\csvautotabularcenter{\jobname.csv}

\bigskip

\csvautobooktabularcenter{\jobname.csv}
\end{document}


Note : The operation on the column counter comes from here