TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a data.txt file and it contains an array of numbers, I included it in the preamble of the .tex file, now I would like to display some specific entry from the data file, not the whole data set but just some of them, how should I do?

share|improve this question
There is no way to do this exactly as you describe, but there are various ways to deal with data of this sort. See Using external tables in TikZ or File input and output or Formatting complex table from CSV using datatool for some examples. – Alan Munn Nov 15 '11 at 3:05
up vote 6 down vote accepted

You can use the PGFplotstable package, which is part of PGFplots, for this.

The data would be loaded into a table macro using \pgfplotstableread{data.txt}\datatable (there are various options for accommodating different data file variants), after which you can access an individual element using \pgfplotstablegetelem{<row>}{<column>}\of\datatable. The element will then be available as \pgfplotsretval.

share|improve this answer
Thanks a lot. Works like a charm. – Shuhao Cao Nov 16 '11 at 1:51

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.