Basically, I have a table (from a file) containing only numeric values. I would like to import in latex but it has to be formatted in a specific way, as illustrated by the picture.

The ... should be replaced by the table content. For example, I have filled the 'Line 1' field with some values coming from the table.

enter image description here

I know that pgfplotstable is a very powerful too but I can't figure how to import it correctly.

The code :


    1.23 2.34  %first line
    2.45 6.54  %first line
    4.56 4.43  %first line
    %Also numeric values for the Line 2 and Line 3


    & Column 1& Column 2\\\hline
Line 1 & 1.23\newline 2.45\newline4.56 &2.34\newline 6.54\newline4.43 \\\hline
Line 2 & ...\newline ...\newline... &...\newline ...\newline...\\\hline
Line 3 & ...\newline ...\newline... &...\newline ...\newline...\\\hline

  • You show your data as single digits "a" and "b". It would be useful to know if they are indeed that, or single words, or phrases. If the data for an element contains blanks, what delimiter will your file have to separate column data? Or is that up to us, and you can create your input file to conform? Sep 25 '13 at 20:25
  • Thanks for pointing out this, I'll make it more precise ! Sep 25 '13 at 20:27
  • See tex.stackexchange.com/questions/117747/… for ideas. Sep 25 '13 at 20:28
  • I have shown a suggestion for a mapping from the number to the fields in the table. It is also possible to combine three different tables. Sep 25 '13 at 20:36
  • An illsutration for the contents in Line 1 : number of students in class A \newline total number of student \newline percentage of students Sep 25 '13 at 20:38

If I'm understanding correctly, this is one way to go. I assumed that the list of class is given somewhere either an extra table column or a list defined as below and indexed by pgfmath function. And I'm hoping that every section has equal (here three) number of rows.

1.23 2.34
2.45 6.54
4.56 4.43
1.23 2.34
2.45 6.54
4.56 4.43
1.23 2.34
2.45 6.54
4.56 4.43
\def\myclasslist{{"Class A","Class C","Class DDD"}}

create on use/class/.style ={create col/set={}},
display columns/1/.style={column name=Column 1},
display columns/2/.style={column name=Column 2},
columns/class/.style={string type,
    column name={},
    assign cell content/.code={%
        \pgfkeys{/pgfplots/table/@cell content/.expanded=\temp}%

enter image description here

  • This works great. However, is there an easy way to make a \hline every 3 lines ? Sep 25 '13 at 21:14
  • @Laurent Add every nth row={3[-1]}{after row=\hline} to the options
    – percusse
    Sep 25 '13 at 21:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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