Graphics, Figures & TablesTikz and multiple input files

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
Anicka
Posts: 13
Joined: Tue Oct 12, 2010 1:20 pm

Tikz and multiple input files

Post by Anicka »

Hallo,

I want to make a plot with vectors going from the coordinate specified in file1 to the coordinate in file2. Can I do this with PGF/Tikz? (Making \draw (x1,y1) -- (x2,y2); is not an option, each file contains 200+ lines.) The files are in the format:
x1 y1
x2 y2
.
.
.

All ideas are welcome!
Last edited by Anicka on Wed Feb 23, 2011 3:48 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

shadgrind
Posts: 140
Joined: Thu Jul 16, 2009 12:39 am

Tikz and multiple input files

Post by shadgrind »

I'm assuming that your two files (call them file1 and file2) have the same number of lines, and in each file the two coordinates are separated by a single space. If so, then if you're on a UNIX-like system an easy way would be to use some UNIX shell utilities (paste and awk) in a terminal window:

Code: Select all

paste file1 file2 | awk '{print "\\draw[->] ("$1","$2") -- ("$3","$4");"}' > mycoords.tex
I tested that on a file1 with these 3 lines

Code: Select all

1 2
4 3
5 0
and a file2 with these 3 lines:

Code: Select all

7 8
10 9
11 0
and it produced the file mycoords.tex consisting of these TikZ commands:

Code: Select all

\draw[->] (1,2) -- (7,8);
\draw[->] (4,3) -- (10,9);
\draw[->] (5,0) -- (11,0);
You could then use \input{mycoords} inside a tikzpicture environment (or copy and paste the contents). There may be a slicker way of having TikZ do it programmatically, but this is my quick and dirty solution. :)
System: TeX Live 2012, Fedora 18 x86_64, GNU Emacs 24.2
Anicka
Posts: 13
Joined: Tue Oct 12, 2010 1:20 pm

Re: Tikz and multiple input files

Post by Anicka »

Thanks!

I ended up doing something similar "by hand", using jedit to insert text by the column.
Post Reply