I want to generate a table with fixed column width. This works for all the columns except for the last column.
Working example (fixed column width for all column except the last one)
\documentclass{article}
\usepackage{array}
\usepackage{csvsimple}
\usepackage{filecontents}
\begin{filecontents*}{grade.csv}
name,givennamex,matriculation,gender,grade
Maier,Hans,12348,m,1.0
Huber,Anna,23456,f,2.3
Weisbaeck,Werner,34567,m,5.0
\end{filecontents*}
\begin{document}
\begin{tabular}{>{\raggedright}m{2cm}|>{\raggedright}m{2cm}|c}%
\bfseries long title column 1 & \bfseries long title column 2 & \bfseries long title column 3% specify table head
\csvreader[head to column names]{grade.csv}{}% use head of csv as column names
{\\\hline\givennamex & \name & \matriculation}% specify your columns here
\end{tabular}
\end{document}
Example with problem (fixed column width for all column including the last one)
\documentclass{article}
\usepackage{array}
\usepackage{csvsimple}
\usepackage{filecontents}
\begin{filecontents*}{grade.csv}
name,givennamex,matriculation,gender,grade
Maier,Hans,12348,m,1.0
Huber,Anna,23456,f,2.3
Weisbaeck,Werner,34567,m,5.0
\end{filecontents*}
\begin{document}
\begin{tabular}{>{\raggedright}m{2cm}|>{\raggedright}m{2cm}|>{\raggedright}m{2cm}}%
\bfseries long title column 1 & \bfseries long title column 2 & \bfseries long title column 3% specify table head
\csvreader[head to column names]{grade.csv}{}% use head of csv as column names
{\\\hline\givennamex & \name & \matriculation}% specify your columns here
\end{tabular}
\end{document}
What can I do to set the width of the last column?
EDIT
After the comments below I added the package ragged2e and changed the first line
\begin{tabular}{>{\raggedright}m{2cm}|>{\raggedright}m{2cm}|>{\raggedright}m{2cm}}%
to this one
\begin{tabular}{>{\raggedright}m{2cm}|>{\raggedright}m{2cm}|m{2cm}}%
Overall, the code is now the following:
\documentclass{article}
\usepackage{array}
\usepackage{csvsimple}
\usepackage{filecontents}
\usepackage{ragged2e}
\begin{filecontents*}{grade.csv}
name,givennamex,matriculation,gender,grade
Maier,Hans,12348,m,1.0
Huber,Anna,23456,f,2.3
Weisbaeck,Werner,34567,m,5.0
\end{filecontents*}
\begin{document}
\begin{tabular}{>{\raggedright}m{2cm}|>{\raggedright}m{2cm}|m{2cm}}%
\bfseries long title column 1 & \bfseries long title column 2 & \bfseries long title column 3% specify table head
\csvreader[head to column names]{grade.csv}{}% use head of csv as column names
{\\\hline\givennamex & \name & \matriculation}% specify your columns here
\end{tabular}
\end{document}
There is still one Problem: I cannot set the last column as centered (I tried to write >{\raggedright}m{2cm} instead of m{2cm} but it doesn't work).

>{\raggedright \arraybackslash}in the last column, or use\tabularnewlineinstead of\\to terminate the lines. – Ulrike Fischer Jul 04 '19 at 07:25