I am trying to fit a table into textwidth using pgfplotstable. The code I found in this forum (here) somehow produces red lines and I do not know why this is the case.

This is how the results looks like. I do not understand what happens top/left. Also do you happen to know how to left-align the columns?

The biggest difference between my code and the code I found is that I am storing my data in a csv file. Any suggestions and solutions are highly appreciated. This is my code:
\usepackage{float}
\usepackage{pgfplotstable,tabularx,booktabs}
\pgfplotsset{compat=1.17}
\begin{document}
\begin{table}
\centering
\caption{\textbf{Caption} }
\label{caption}
\footnotesize
\pgfplotstabletypeset[
column type=,
begin table={\begin{tabularx}{\textwidth}{X c c c c}},
end table={\end{tabularx}},
multicolumn names, % allows to have multicolumn names
col sep=comma, column type={l}, % the separator in the .csv file + column raggedleft
display columns/0/.style={ column name=$ $, %first column because it is string type
column type={l},string type},
every head row/.style={
before row= \toprule,% have a rule at top
after row={
\si{\ampere} & \si{\volt}\ % the units separated by &
\midrule} % rule under units
},
every last row/.style={after row=\bottomrule}, % rule at bottom
]{Datafile.csv} % filename/path to file
\raggedright
\newline
\footnotesize{\textit{Sources}}
\end{table}
\end{document}
\documentclass. It also looks like you want to add\usepackage{situnitx}. Please include the csv file as well – mbert Nov 09 '22 at 17:25