The Stata tutorial code that I am using generates its outputs in .txt files. (I can also choose the option to let the code generate its outcome in .tex files.) I want to insert this outcome in my latex code. Is there a way to insert this outcome and make this appear in the table format?
The text file looks like this: (This prevents me from using "\verbatiminput" or "\input")
Mean Median SD Min Max Count
Price 6,165.3 5,006.5 2,949.5 3,291.0 15,906.0 74
MPG 21.3 20.0 5.8 12.0 41.0 74
Weight 3,019.5 3,190.0 777.2 1,760.0 4,840.0 74
Any help will be highly appreciated!
Texmaker and TeXstudio ⇒ How to insert text from an external file (.txt or .tex)
NEW: TikZ book now 40% off at Amazon.com for a short time.
- Stefan Kottwitz
- Site Admin
- Posts: 10324
- Joined: Mon Mar 10, 2008 9:44 pm
How to insert text from an external file (.txt or .tex)
Welcome to the forum!
The
datatool package can be used for this. An example of the upcoming LaTeX Cookbook used this file:
Then it used this code as example:
It reads in that file, and constructs a table from it:
You can use more complex tables, and tabs can be chosen as field separator as well by using the command
Stefan
The

Distribution,Hits
Mint,2364
Ubuntu,1838
Debian,1582
openSUSE,1334
Fedora,1262
Mageia,1219
CentOS,1171
Arch,1040
elementary,899
Zorin,85
Then it used this code as example:
Code: Select all
\documentclass{article}
\usepackage{booktabs}
\usepackage{datatool}
\DTLloaddb{Linux}{linux.csv}
\DTLsort[Distribution]{Hits=descending}{Linux}
\pagestyle{empty}
\begin{document}
\begin{tabular}{rlr}
& Distribution & Hits \\
\cmidrule(lr){2-2}\cmidrule(lr){3-3}
\DTLforeach{Linux}{%
\distribution=Distribution,\hits=Hits}{%
\theDTLrowi & \distribution & \hits \\}
\end{tabular}
\end{document}
You can use more complex tables, and tabs can be chosen as field separator as well by using the command
\DTLsettabseparator
.Stefan
LaTeX.org admin