Hot answers tagged

64

If you need to plot data from files, I think you'll be much happier if you use PGFPlots instead of the native plot functionality of TikZ. Here's a very simple example of plotting your example data to get you started. PGFPlots is very customizable, you can tweak virtually every aspect of your plots, and it's much more user-friendly than if you tried to knit ...


51

The csvsimple manual describes it. This is an modified example from the manual. \documentclass{standalone} \usepackage{csvsimple} \begin{filecontents*}{grade.csv} name,givenname,matriculation,gender,grade Maier,Hans,12345,m,1.0 Huber,Anna,23456,f,2.3 Weisbaeck,Werner,34567,m,5.0 \end{filecontents*} \begin{document} \begin{tabular}{l|c}% \bfseries ...


25

You can use pgfplotstable or datatool which I think csvsimple comes from. Here is an example with pgfplotstable with default settings. \documentclass{standalone} \usepackage{pgfplotstable,filecontents} \pgfplotsset{compat=1.9}% supress warning \begin{filecontents*}{test.csv} Time (s),Zeroed time (s),Y Position in pixels,Zeroed Y Position in pixels,Y ...


23

You can use the PGFPlots statistics library for this: \documentclass[border=5mm]{standalone} \usepackage{filecontents} \usepackage{pgfplots, pgfplotstable} \usepgfplotslibrary{statistics} \begin{filecontents}{data.csv} dist 1 2 2.5 2 1 3.5 3 1 3 2 1 1 0.5 1 1.5 1 \end{filecontents} \begin{document} \begin{tikzpicture} \begin{axis}[ ybar, ymin=0 ] \...


16

You need to create a column specification for that. \documentclass{article} \usepackage{pgfplotstable} \pgfplotstableread[col sep=comma]{ Name, Age, stDev Adam, 15, 3 Eve, 12, 1 }\mytable \begin{document} \pgfplotstabletypeset[ create on use/unc age/.style={ create col/assign/.code={% \edef\entry{\thisrow{Age}$\pm$\thisrow{stDev}} \...


16

I don't know how to do it using pgfplotstable, but here's how to do it with datatool: Edit: Updated to round to 2 d.p. \documentclass{article} \usepackage{datatool} \begin{filecontents*}{test.csv} Name, Age, stDev Adam, 15.00201, 3.00601 \end{filecontents*} \DTLloaddb{mydata}{test.csv} % Round to 2 dp and display. % (More efficient to use \dtlround ...


15

If you do not have names for the columns in your csv file (i.e. in a header row) you can use the column indices, starting with zero to refer to them. See page 49 of version 1.10 of the pgfplots manual \documentclass[tikz]{standalone} \usepackage{pgfplots} \pgfplotsset{compat = 1.10} \pgfplotstableread[col sep = comma]{fexam1cdata.csv}\mydata \begin{document}...


12

This is exactly the same problem I and my classmates were having when writing our lab reports on Experimental Physics. Since we work in groups it's great to have data on the cloud. The problem was converting sometimes dozens of tables to Latex... So, I and a classmate of mine came up with LatexKit, a google sheets add-on that creates and exports to your ...


11

You want to use longtable: \documentclass{article} \usepackage{csvsimple,longtable,booktabs} \begin{document} \csvreader[ longtable=lrrrr, table head=\toprule\bfseries Item &\bfseries Alpha category (\%) \\\midrule, late after line=\\, late after last line=\\\bottomrule, before reading={\catcode`\#=12},after reading={\catcode`\#=6} ]{...


10

To get a linear regression line for data from a data file, use \addplot [no markers] table [y={create col/linear regression={y=<column name>}}] {<file name>}; \documentclass[border=5mm]{standalone} \usepackage{pgfplots, pgfplotstable} \usepackage{filecontents} \begin{filecontents}{table.dat} x y 0 1 100 3 150 2 200 5 300 6 \end{filecontents} ...


9

EDIT: After the OP stressed again that he want to use existing colormap from pgfplots, I think it might be better for him to use \pgfplotstabletypeset with a bit of preprocessing of csv. However, if you're like me who is more comfortable with tikz/pgf and python, then the answer below should provide more flexibility. The one thing I'm not satisfied with ...


9

Assuming that your .tex file is called mytable.tex, and looks like this: \ifdefined\mycsvfile \else \def\mycsvfile{csv1.csv} \fi \documentclass[a4paper,10pt]{article} \usepackage{pgfplotstable, booktabs} \begin{document} \begin{center} \pgfplotstabletypeset [ col sep = comma, every head row/.style={before row=\toprule, after row=\midrule}, ...


8

It seems that it's impossible to call csvreader inside \draw plot coordinates { }. To avoid the plot command and still being able to plot lines between points, I need to use xdef to remember the previous point. \begin{filecontents*}{data.csv} a,b,c,d 1,4,5,1 2,3,1,5 3,5,6,1 4,1,4,9 5,3,4,7 \end{filecontents*} \documentclass{article} \usepackage[utf8]{...


8

The datatool package also comes with the command \DTLloadrawdb which is like \DTLloaddb but maps special characters, such as #, to a command, such as \#. However, there's an added problem here. The column labels by default are set to the corresponding header title in the CSV file, but as these labels are used to construct control sequences (via \csname...\...


8

You need to use a longtable rather than a tabular environment. If you use longtable's native syntax, it's straightforward to retain full control over objects such as header and footer material on every page. Naturally, as @egreg's parallel answer shows, it's possible to do so using csvreader's syntax as well. \documentclass{article} \usepackage{booktabs,...


8

Add \usepackage[T1]{fontenc} The default OT1 encoding doesn't have ascii symbols in the places you might expect.


7

The service http://www.tablesgenerator.com/ lets you create latex-based tables in a GUI and then export the code. It also lets you upload a CSV and converts it aut


7

Here's a possible solution: \documentclass{article} \usepackage{eso-pic} \usepackage{fancyhdr} \usepackage{blindtext} % just for the example \usepackage[headsep=3cm,top=5cm]{geometry} \usepackage{datatool} % create sample csv file \begin{filecontents*}{test.csv} Id,myauthor,mydate,myaddress 1,Sebastian,12.12.2012,XYZ road,XYZ city 2,Rose,12.12.2013,XYZ ...


7

You can first of all use a macro to hold the name of the .csv file in abc.tex: \documentclass{article} \usepackage{datatool} \begin{document} ... \DTLloaddb[noheader,keys={Temperature,Time,T2G}]{data}{\csvname.csv} ... \end{document} Then you can call xelatex from the command line by saying xelatex -jobname=abc-pqr '\def\csvname{pqr}\input{abc}' ...


7

If you are prepared to use pgfplotstable then this can be done. It contains a construct to divide columns in to equal parts to simulate multicolumn tables, namely select equal part entry of. Dividing in to two columns is achieved with the first column being given style select equal part entry of={0}{2} and the second select equal part entry of={1}{2}. You ...


7

TeX can be instructed to ignore a character, by assigning it the category code 9. This will not affect usages of \" in the file. \begin{filecontents*}{\jobname.csv} "1st field", "numerical field", "string field" "foo", 3, "bar" "xizzy", 0, "lorem ipsum" "nothing", 1,"last string" \end{filecontents*} \documentclass{article} \usepackage{csvsimple} \begin{...


7

Omitting the key in columns removes that column \documentclass{article} \usepackage[letterpaper, margin=0.5in]{geometry} \usepackage{pgfplotstable} \begin{document} \pgfplotstabletypeset[ col sep=comma, columns={Name,{para c},{para d}}, columns/Name/.style={column type={r},string type}, columns/{para a}/.style={column type={r},string type}, ...


7

You have to describe the structure of the csv file to pgfplotstable. And you have subscripts in your column/row names that you need to take care of. I've just removed them. \documentclass{scrreprt} \usepackage{pgfplotstable,booktabs} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% You don't need this part % I did it to create your file \usepackage{...


6

A part for the error that contains the date that is fixed following the comment of @Ulrike Fischer (by substituting \input{fp} with \RequirePackage{fp} into the invoice.sty file), the main error is in the \DTLforeach command. You don't have to add an argument for each field in your .csv file but group them all in the same argument of \DTLforeach. Also in ...


6

It seems that it is not implemented but can be done with some labor. I've modified the existing macros rather too quickly so Christian should know if I'm breaking anything here. The new setting can be used via col sep=double quotes. But it doesn't support another column with quotes as it is an ambiguous character for opening and closing. \documentclass{...


6

Adding \expanded around the \chapter{...} call solves your problem. Inspecting the .tuc file shows that chapter titles are written to the chapter list (which is a Lua table) as "\\insert [Name]", i.e. as the unexpanded input. \expanded{...} expands its contents (deepest-first); now, \chapter only sees the far less problematic Ms. Premise (for example). \...


6

You may use (axis cs:x,y) as point: \documentclass[10pt,twocolumn]{article} \usepackage{graphicx} \usepackage{pgfplots} \usepackage{tikz} \begin{document} \begin{tikzpicture} \begin{axis}[] \addplot[line width = 0.5pt] table [mark=none,col sep=comma,] {cicloexane.csv}; \draw [<-] (axis cs:801.3,6066)-- +(10pt,10pt) node[right] {here}; \end{axis} \end{...


6

Here's a way with expl3 and Heiko Oberdiek's catchfile: \documentclass{article} \usepackage[T1]{fontenc} % for the underscore \usepackage{catchfile} \usepackage{xparse} \ExplSyntaxOn \cs_set_eq:NN \egreg_catchfiledef:nnn \CatchFileDef \cs_generate_variant:Nn \egreg_catchfiledef:nnn { c } \cs_generate_variant:Nn \seq_set_split:Nnn { Nnv } \...


6

pgfplots, comb plot Thanks to Torbjørn T., who has suggested to look at comb plots. This allowed me to plot 7150 (but not 7200) data points: gnuplot crosses You have to create a file that tells gnuplot what to do. I've called it plot.gnuplot: set terminal latex set output "plot-tmp.tex" set datafile separator "," set title "Collatz Number of steps" ...


6

I would suggest using the datatool package (click the image to enlarge it): \documentclass{article} \usepackage{filecontents} \begin{filecontents*}{sample.csv} Name, Address, City, State, Zip Company 1, 5555 N 5th St, Townsville, CA, 55555 Company 2, 5556 N 5th St, Townsville, CA, 55556 Company 3, 5557 N 5th St, Townsville, CA, 55557 \end{filecontents*} \...


Only top voted, non community-wiki answers of a minimum length are eligible