[Tex/LaTex] Is it possible to make a pgfplotstable smaller? Reduce spaces and maybe draw vertical lines between columns

pgfplotstable

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.

Adding

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[
 every head row/.style={
 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,
header=false
]
{
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:

table

Best Answer

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,
    every head row/.style={
    ...

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:

enter image description here

Related Question