是否可以将 pgfplotstable 做得更小一些?减少空间,或者在列之间画垂直线?

是否可以将 pgfplotstable 做得更小一些?减少空间,或者在列之间画垂直线?

我的表格太大,放不下一页,所以我想把它弄小一点。也许可以减少每列之间的间距,然后画一条线。

添加

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

加上垂直线后表格看上去好多了,但是还是太大了。

这是代码,其中还有更多数据,但我删除了一些,因此代码不会很长:

\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}

结果:

桌子

答案1

这里有两个问题:

  1. 你的表格太长,一页放不下
  2. 它也太宽了

对于第一个问题,您可以通过使用longtable包(单独使用或与tabu包一起使用longtabu)添加以下内容来解决这个问题:

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

到您的序言中,并将下表定义添加到\pgfplotstabletypeset

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

或者

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

对于第二个问题,您可以通过将 pfgtable 包含到一个块中并{}发出\small或等效命令来更改字体大小,或者使用graphicx包并将表格宽度缩放\linewidth

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

编辑

根据 @polar 的评论,确实如此,longtable因此longtabu无法放入调整大小的框中。(抱歉,我没有认真考虑)。

然而,使用longtabu功能,我们可以让表格适应,尽管需要一些字体大小调整:

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

使用下面的代码将生成一个适合宽度和边距的表格(注释掉font一行默认的类,article在默认的字体大小下给出overfull hbox.6pt的大小。

如果您不了解tabu语法,请解释加密列定义

  • @{}删除行首和行末的空格(不tabu具体)
  • c是正常的居中列
  • *6{}定义 6 列宽度包含的定义
  • X[c]定义可伸缩列以帮助表格适应命令指定的所需to \linewidth宽度

此外,您还需要该skip coltypes=false,行,否则pgfplotstable会添加默认{ccccccccc}定义。

为您提供:

在此处输入图片描述

答案2

ArTourter 的答案被接受了,但是对于那些来这里并且认为太复杂或太长的人来说,我已经调整了他的第一个解决方案,即 resizebox 解决方案,它不适用于 pgfplotstable,但适用于 latex 的表格:

\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}

输出:

输出

由于我把桌子做得短了很多,所以我不再需要使用长桌了,但如果你的桌子很长,请按照 ArTourter 建议的方式使用它。

答案3

在我看来,ArTourter 提出的解决方案不适用于大于文本宽度的表格。我有以下代码

\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,
    header=false
]
{
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 
}

跨多页的拆分是受尊重的,但表格未调整大小。第一列完全显示,但其他列位于其他列之上,使其无法读取。我还没有找到这种拆分调整大小的任何解决方案。我不得不在调整大小或拆分之间做出选择。如果有人有解决方案...

相关内容