Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have a datatable in a CSV file and print it with pgfplotstable. I can split long datatables by making pgfplotstable use longtable instead of tabular environment; so far so good. My problem is that my datatable has only two columns, hence it results in pages like:

+-------------------------+
|          XX XX          |
|          XX XX          |
|          XX XX          |
|          XX XX          |
|          XX XX          |
|                         |
|                         |
+-------------------------+

The point is: left and right of the table there is much free space. I would like the table being printed as:

+-------------------------+
|  XX XX | XX XX | XX XX  |
|  XX XX | XX XX | XX XX  |
|  XX XX | XX XX | XX XX  |
|  XX XX | XX XX | XX XX  |
|  XX XX | XX XX | XX XX  |
|  XX XX | XX XX | XX XX  |
|  XX XX | XX XX | XX XX  |
|                         |
|                         |
+-------------------------+

I know that I can achieve this by using solutions like multicolumn long table or enumeration, but this has to disadvantages:

  • I have to manually specify the number of columns to use
  • the columns are not balanced
  • I cannot use this inside a float like table

So, my question is: Is there a package that provides this feature, holding the above three points?

share|improve this question
1  
Welcome to TeX.sx! Please add a minimal working example (MWE) that illustrates your problem. While showing illustrations are useful for explaining, it will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. –  hpesoj626 Mar 20 '13 at 16:03
    
/pgfplots/table/select equal part entry of={<part no>}{<part count>} pgfplotstable manual, page 40. –  Harish Kumar Mar 20 '13 at 16:22
1  
See if this answers your question, if so we could close this as duplicate: tex.stackexchange.com/questions/45980/… –  David Carlisle Mar 20 '13 at 16:25

1 Answer 1

You can use /pgfplots/table/select equal part entry of={<part no>}{<part count>}, refer pgfplotstable manual, page 40. This code is taken from the manual with some modifications.

\documentclass{article}
\usepackage{pgfplotstable}
\usepackage{booktabs}
\usepackage{filecontents}
\begin{filecontents*}{pgfplotstable.example2.dat}
A B
A1 B1
A2 B2
A3 B3
A4 B4
A5 B5
A6 B6
A7 B7
A8 B8
A9 B9
A10 B10
A11 B11
A12 B12
A13 B13
A14 B14
A15 B15
A16 B16
A17 B17
A18 B18
A19 B19
A20 B20
A21 B21
\end{filecontents*}
\begin{document}
\pgfplotstableset{
every head row/.style={before row=\toprule,after row=\midrule},
every last row/.style={after row=\bottomrule}}
\pgfplotstabletypeset[string type]{pgfplotstable.example2.dat}%
%
\pgfplotstabletypeset[
columns={A,B,A,B},
display columns/0/.style={select equal part entry of={0}{2},string type},% first part of ‘A’
display columns/1/.style={select equal part entry of={0}{2},string type},% first part of ‘B’
display columns/2/.style={select equal part entry of={1}{2},string type},% second part of ‘A’
display columns/3/.style={select equal part entry of={1}{2},string type},% second part of ‘B’
]{pgfplotstable.example2.dat}

\end{document}

enter image description here

You can change the number of columns (parts) easily by changing part no and part count. For example to have three parts we do:

\pgfplotstabletypeset[
columns={A,B,A,B,A,B},
display columns/0/.style={select equal part entry of={0}{3},string type},% first part of ‘A’
display columns/1/.style={select equal part entry of={0}{3},string type},% first part of ‘B’
display columns/2/.style={select equal part entry of={1}{3},string type},% second part of ‘A’
display columns/3/.style={select equal part entry of={1}{3},string type},% second part of ‘B’
display columns/4/.style={select equal part entry of={2}{3},string type},% third part of ‘A’
display columns/5/.style={select equal part entry of={2}{3},string type},% third part of ‘B’
]{pgfplotstable.example2.dat}

enter image description here

share|improve this answer
    
Thank you. Indeed that is what I was looking for. I overlooked it in the manual. –  Bubaya Mar 22 '13 at 18:42

Your Answer

 
discard

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.