I have txt file with table format, I did it in python but now I have to export this table to Latex but I don't know how. I'm not good at all in latex so I'll appreciate if you help me.
Thank you!
I have txt file with table format, I did it in python but now I have to export this table to Latex but I don't know how. I'm not good at all in latex so I'll appreciate if you help me.
Thank you!
There are several ways to do it, here are some of them:
1. according to @Teddy van Jerry using pgfplotstable
Your .txt file:
x y
1 2
2 4
3 6
4 8
Your .tex file
\documentclass{article}
\usepackage{pgfplotstable}
\begin{document}
\pgfplotstabletypeset[
col sep=space,
columns={x,y},
columns/x/.style={column name=$x$, column type={|c}},
columns/y/.style={column name=$y$, column type={c|}},
every head row/.style={before row=\hline, after row=\hline},
every last row/.style={after row=\hline},
]{data.txt}
\end{document}
Result
2. Using \usepackage{csvsimple}
Your .txt file:
Name, Age, Gender
John, 30, Male
Sarah, 25, Female
Bob, 45, Male
Your .tex file
\documentclass{article}
\usepackage{csvsimple}
\begin{document}
\begin{table}[h]
\centering
\csvreader[ tabular=|c|c|c|, table head=\hline Name & Age & Gender \\hline, late after line=\\hline, ]{data.txt}{Name=\name,Age=\age,Gender=\gender}{\name & \age & \gender}
\end{table}
\end{document}
Result
pgfplotstablewhich can take a txt file input. – Teddy van Jerry May 02 '23 at 17:26