Is it possible to make a pgfplotstable smaller? Reduce spaces and maybe draw vertical lines between columns?

My table is too big and won't fit a page, so I wanted it to be a little smaller. Maybe reduce spaces between each column and draw a line instead.

column type/.add={|}{}% results in '|c'


put the vertical lines and the table looked better, but it's still too big.

Here's the code, there are more data to it, but I removed some so the code wouldn't be huge:

\documentclass{article}
\usepackage{booktabs}
\usepackage{pgfplotstable}
%\usepackage[paperwidth=35cm]{geometry}

\begin{document}

\pgfplotstabletypeset[
before row={\toprule
& &
&\multicolumn{2}{c}{32-2}
&\multicolumn{2}{c}{128-4}
&\multicolumn{2}{c}{256-8}\\
},
after row=\midrule
},
display columns/0/.style={column name={Instance}},
display columns/1/.style={column name={n}},
display columns/2/.style={column name={m}},
display columns/3/.style={column name={Avg. Time.}},
display columns/4/.style={column name={Avg. Qual.}},
display columns/5/.style={column name={Avg. Time.}},
display columns/6/.style={column name={Avg. Qual}},
display columns/7/.style={column name={Avg. Time.}},
display columns/8/.style={column name={Avg. Qual.}},
every last row/.style={after row=\bottomrule},
string type,
]
{
hp1.dat    28   4   3.7960  0.9763  5.8166  0.9850  8.0020  0.9895
hp2.dat 35  4   4.0924  0.9673  6.8730  0.9696  9.9091  0.9717
pb1.dat 27  4   3.4976  0.9843  5.2666  0.9890  7.5312  0.9947
pb2.dat 34  4   4.1574  0.9730  7.3916  0.9783  10.5208 0.9812
pb4.dat 29  2   2.9995  0.9996  4.3949  1.0000  6.1613  1.0000
pb5.dat 20  10  2.7515  0.9782  3.6325  0.9820  4.9027  0.9868
pb6.dat 40  30  3.7279  0.9088  5.2931  0.9034  7.5250  0.9093
pb7.dat 37  30  5.9737  0.9894  9.8045  0.9833  14.3086 0.9865
}

\end{document}


Result:

-

Here you have two issues:

1. your table is too long to fit in one page
2. it is also too wide

For the first problem, you can fix this by using the longtable package (alone or with the tabu package as longtabu) by adding

\usepackage{longtable}
\usepackage{tabu} % if you want


to your preamble, and adding the following table definition to the \pgfplotstabletypeset:

\pgfplotstableset{
begin table=\begin{longtable},
end table=\end{longtable},
}


or

\pgfplotstableset{
begin table=\begin{longtabu},
end table=\end{longtabu},
}


for the second problem, you can either change the font size by including your pfgtable into a block {} and issuing a \small or equivalent, or using the graphicx package and scale the table width to \linewidth with

\resizebox{\linewidth}{!}{\pgfplotstabletypeset[...]
{...}
}


EDIT

Following the comment by @polar, indeed, longtable and therefore longtabu cannot be fit into a resize box. (Sorry about that I had not thought hard enough).

However using longtabu functionality, we can get the table to fit albeit with the help of some font resizing:

\pgfplotstabletypeset[
font={\small},
begin table=\begin{longtabu} to \linewidth {@{}ccc*6{X[c]}@{}},
end table=\end{longtabu},
skip coltypes=true,
...


using the following code will produce a table that fits width the margins (commenting the font line one a default article class at default font size give a overfull hbox of .6something pt.

To explain the crypting column definition if you are not aware of tabu's syntax

• @{} gets rid of the space at the beginning and the end of the row (not tabu specific)
• c is your normal centred column
• *6{} defines 6 columns width the included definition
• X[c] defines a stretchable column to help fit the table to the desired width as specified with the to \linewidth command

Additionally you need the skip coltypes=false, line as otherwise pgfplotstable adds the default {ccccccccc} definition.

Giving you:

-
The width fix code isn't working. It outputs an empty page. I have this: \resizebox{\linewidth}{!}{\pgfplotstabletypeset[]{} } –  polar Dec 7 '12 at 17:08
\pgfplotstabletypeset[]{} has the whole code in it, i just omitted, so \pgfplotstabletypeset[...]{...}. –  polar Dec 7 '12 at 17:22
Can't make it work with pgfplotstable. It does works with tabular tables. –  polar Dec 7 '12 at 17:38
See my updated answer. –  ArTourter Dec 7 '12 at 21:03

ArTourter's anwer was accepted, but for anyone who comes here and think that is too complicated or long, I have adapted his first solution, the resizebox one, that doesn't work with pgfplotstable, but does work with latex's tabular:

\documentclass{standalone}
\usepackage{booktabs}
\usepackage{pgfplotstable}
\usepackage{graphicx}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\begin{document}

\resizebox{\linewidth}{!} {
\begin{tabular}{cccccccc}
\hline
& & \multicolumn{2}{c}{32-2} & \multicolumn{2}{c}{128-4} & \multicolumn{2}{c}{256-8} \\
\cmidrule(r){3-4} \cmidrule(r){5-6} \cmidrule(r){7-8}
\begin{tabular}{l}Nome do conjunto\\de problemas\end{tabular} & \begin{tabular}{l}Número de\\problemas\end{tabular} & \begin{tabular}{l}Tempo médio \\de execução\end{tabular} & \begin{tabular}{l}Qualidade média\\das soluções\end{tabular} & \begin{tabular}{l}Tempo médio\\de execução\end{tabular} & \begin{tabular}{l}Qualidade média\\das soluções\end{tabular} & \begin{tabular}{l}Tempo médio \\de execução\end{tabular} & \begin{tabular}{l}Qualidade média\\das soluções\end{tabular} \\
\midrule
HP & 2 & 1,9829 & 0,9658 & 3,2232 & 0,9663 & 4,4793 & 0,9769 \\
PB & 6 & 1,9262 & 0,9652 & 3,0170 & 0,9668 & 4,2623 & 0,9719 \\
PETERSEN & 7 &1,8596 & 0,9939 & 3,0998 & 0,9935 & 4,5300 & 0,9949 \\
SENTO &  2 &4,8483 & 0,9930 & 9,5959 & 0,9924 & 14,5512 & 0,9936 \\
WEING  &  8 &2,5777 & 0,9991 & 6,3547 & 0,9997 & 9,4898 & 0,9999 \\
WEISH &  30 & 2,8594 & 0,9905 & 5,9862 & 0,9883 & 9,2029 & 0,9898 \\
\bottomrule
\end{tabular}
}

}
\end{document}


Output:

Since I made the table a lot shorter, I don't need to use the longtable anymore, but if your table is long, use it like ArTourter suggested.

-

It seems to me that the solution proposed by ArTourter does not work with a table larger than your textwidth. I have following code

\pgfplotstabletypeset[
font={\small},
begin table=\begin{longtabu} to \linewidth {@{}l*6{X[c]}@{}},
end table=\end{longtabu},
skip coltypes=true,
col sep=comma,
string type,
]
{
ALIZE 1954/10488/CMA/BXL/HEERK & 2009  & T     & 0     & 0     & 0     & 0
ALIZE 1955/10488/CMA/BXL/HEERK & 2009  & T     & 0     & 0     & 0     & 0
ALIZE 1956/10488/CMA/BXL/HEERK & 2009  & T     & 0     & 0     & 0     & 0
ALIZE 1957/10488/CMA/BXL/HEERK & 2009  & T     & 0     & 0     & 0     & 0
ALIZE 1992/10488/CMA/BXL/HEERK & 2009  & F     & 0     & 0     & 0     & 0
ALIZE 1993/10488/CMA/BXL/HEERK & 2009  & T     & 0     & 0     & 0     & 0
ALIZE 1994/10488/CMA/BXL/HEERK & 2009  & T     & 0     & 0     & 0     & 0
ALIZE 1995/10488/CMA/BXL/HEERK & 2009  & T     & 0     & 0     & 0     & 0
ALIZE 1996/10488/CMA/BXL/HEERK & 2009  & T     & 0     & 0     & 0     & 0
ALIZE 1997/10488/CMA/BXL/HEERK & 2009  & T     & 0     & 0     & 0     & 0
ALIZE 1998/10488/CMA/BXL/HEERK & 2009  & T     & 0     & 0     & 0     & 0
ALIZE 1999/10488/CMA/BXL/HEERK & 2009  & T     & 0     & 0     & 0     & 0
ALIZE 54/57/10488/CMA/BXL/HEERK & 2009  & T     & 0     & 0     & 0     & 0
ALIZE 92-99/10488/CMA/BXL/HEERK & 2009  & T     & 0     & 0     & 0     & 0
AMERASIA 1 S N C/10403/CMA/BXL/HEERK & 2009  & T     & 0     & 0     & 0     & 0
AMERASIA 2 S N C/10403/CMA/BXL/HEERK & 2009  & T     & 0     & 0     & 0     & 0
AMERASIA 3 S N C/10403/CMA/BXL/HEERK & 2009  & T     & 0     & 0     & 0     & 0
AMERASIA 4 S N C/10403/CMA/BXL/HEERK & 2009  & T     & 0     & 0     & 0     & 0
AMERASIA 5 S N C & 2009  & T     & 0     & 0     & 0     & 0
AMERASIA 6 S N C & 2009  & T     & 0     & 0     & 0     & 0
ALIZE 1954 & 2012  & T     & 0     & 0     & 0     & 0
ALIZE 1955 & 2012  & T     & 0     & 0     & 0     & 0
ALIZE 1956 & 2012  & T     & 0     & 0     & 0     & 0
ALIZE 1957 & 2012  & T     & 0     & 0     & 0     & 0
ALIZE 1993 & 2012  & T     & 0     & 0     & 0     & 0
ALIZE 1994 & 2012  & T     & 0     & 0     & 0     & 0
ALIZE 1995 & 2012  & T     & 0     & 0     & 0     & 0
ALIZE 1996 & 2012  & T     & 0     & 0     & 0     & 0
ALIZE 1997 & 2012  & T     & 0     & 0     & 0     & 0
ALIZE 1998 & 2012  & T     & 0     & 0     & 0     & 0
ALIZE 1999 & 2012  & T     & 0     & 0     & 0     & 0
ALIZE 54/57 & 2012  & T     & 0     & 0     & 0     & 0
CAROLINE 30 & 2012  & T     & 0     & 0     & 0     & 0
CAROLINE 31 & 2012  & T     & 0     & 0     & 0     & 0
CAROLINE 32 & 2012  & T     & 0     & 0     & 0     & 0
LA SCALA BAIL & 2012  & T     & 0     & 0     & 0     & 0
}


The split across multiple pages is respected but the table is not resized. First column appears totally but the others are ones on the others making them unreadable. I have not found any solution for this split-resize. I had to make a choice between one of them either the resize or the split. If anyone has a solution...

-
Welcome to TeX.sx! Your question won't be seen by many people here, so it would be best to repost it as a fresh question. Follow-up questions like this are more than welcome! Please use the "Ask Question" link for your new question; there you can link to this question to provide the background. BTW: Have you tried longtableinstead of longtabu? –  Kurt Apr 15 '13 at 8:39
god I hate tables in latex. –  Nicholas Hamilton Oct 26 '13 at 5:51