将数字数组打印到多列中

将数字数组打印到多列中

我有 100 个数字,我想在一页中将这些数字打印在多列中,如下所示:

1 11 21........91
2 12 22........92
3 13 23........93
4 14 24........94
5 15 25........95
6 16 26........96
7 17 27........97 
.................
.................
10 20 30 ..... 100

更准确地说,我想在一页中将我的数据打印为{10 行 * 10 列}。我的数据存储在 .csv 文件中。数据存储格式如下:

4.00E+00
5.00E+00
4.00E+00
5.00E+00
4.00E+00
6.00E+00
4.00E+00
1.00E+01
4.00E+00
4.00E+00
5.00E+00
4.00E+00
7.00E+00
4.00E+00
4.00E+00
5.00E+00
4.00E+00
5.00E+00
4.00E+00
6.00E+00
5.00E+00
4.00E+00
4.00E+00
6.00E+00
4.00E+00
5.00E+00
4.00E+00
4.00E+00
9.00E+00
4.00E+00
4.00E+00
5.00E+00
5.00E+00
4.00E+00
4.00E+00
4.00E+00
4.00E+00
5.00E+00
4.00E+00
4.00E+00
4.00E+00
4.00E+00
4.00E+00
4.00E+00
4.00E+00
4.00E+00
4.00E+00
4.00E+00
4.00E+00
6.00E+00
5.00E+00
4.00E+00
1.10E+01
5.00E+00
4.00E+00
4.00E+00
4.00E+00
6.00E+00
5.00E+00
4.00E+00
4.00E+00
4.00E+00
5.00E+00
4.00E+00
4.00E+00
4.00E+00
4.00E+00
4.00E+00
6.00E+00
5.00E+00
7.00E+00
5.00E+00
5.00E+00
4.00E+00
5.00E+00
4.00E+00
4.00E+00
5.00E+00
4.00E+00
4.00E+00
6.00E+00
4.00E+00
7.00E+00
4.00E+00
4.00E+00
8.00E+00
1.20E+01
4.00E+00
4.00E+00
8.00E+00
4.00E+00
4.00E+00
4.00E+00
4.00E+00
4.00E+00
6.00E+00
8.00E+00
4.00E+00
4.00E+00
4.00E+00
6.00E+00
5.00E+00
6.00E+00
5.00E+00
5.00E+00
9.00E+00
4.00E+00
4.00E+00
4.00E+00
4.00E+00
5.00E+00
5.00E+00
4.00E+00
8.00E+00
4.00E+00
1.50E+01
4.00E+00
4.00E+00
6.00E+00
4.00E+00

。我尝试使用 pgfplotstable,但无法将数据分成多列。我只得到单列。

我使用的代码是:

\documentclass{article}
\usepackage{pgfplotstable}
\usepackage{longtable}
\pgfplotsset{compat=1.11} 
\pgfplotstableread[col sep = comma]{x_values.csv}\mydata

\begin{document}

\pgfplotstableread[
  col sep=comma,
    ]{x_values.csv}{\fionasData}

\pgfplotstabletypeset[
    every head row/.style={output empty row},
    begin table=\begin{longtable},
  end table=\end{longtable},
]{\fionasData}

\end{document}

有人能给出建议吗?

答案1

readarray包需要空格分隔的数据(我需要更改该功能)。但由于文件中的数据是单列提供的,因此 csv 文件中没有逗号,空格/行分隔足以解析数据。

已编辑,使“表格”居中。

这使用指定格式的输入文件 Book1.csv:

1
2
3
...
98
99
100

以下是 MWE:

\documentclass{article}
\usepackage{readarray,ifthen}
\newcounter{rowindex}
\newcounter{colindex}
\begin{document}
\def\mycols{10}
\readdef{Book1.csv}{\mydata}
In this file there were \nrows\ row(s) and \ncols\ column(s) of data

I will read it into an array of \mycols\ columns.
\readArrayij{\mydata}{data}{\mycols}

There are \dataCELLS\ cells in the array, made up of
\dataROWS\ rows and \dataCOLS\ columns.

And here is the table, centered

\begin{center}
\whiledo{\therowindex<\mycols}{%
  \stepcounter{rowindex}%
  \setcounter{colindex}{0}%
  \whiledo{\thecolindex<\dataCOLS}{%
    \stepcounter{colindex}%
%    \arrayij{data}{\thecolindex}{\therowindex}\ % <--- Add desired seperator
    \makebox[.7cm][r]{\arrayij{data}{\thecolindex}{\therowindex}}% or use Fixed width
  }\par
}
\end{center}
For comparison, here are the margin delimiters\par
\noindent\hrulefill
\end{document}

该行\arrayij可以使用分隔符或数据单元的框;我使用了一个框。

在此处输入图片描述


如果人们不想要center环境中的额外垂直空间……

\documentclass{article}
\usepackage{readarray,ifthen}
\newcounter{rowindex}
\newcounter{colindex}
\begin{document}
\def\mycols{10}
\readdef{Book1.csv}{\mydata}
In this file there were \nrows\ row(s) and \ncols\ column(s) of data

I will read it into an array of \mycols\ columns.
\readArrayij{\mydata}{data}{\mycols}

There are \dataCELLS\ cells in the array, made up of
\dataROWS\ rows and \dataCOLS\ columns.

And here is the table, centered

{\parindent0pt\relax
\centering
\whiledo{\therowindex<\mycols}{%
  \stepcounter{rowindex}%
  \setcounter{colindex}{0}%
  \whiledo{\thecolindex<\dataCOLS}{%
    \stepcounter{colindex}%
%    \arrayij{data}{\thecolindex}{\therowindex}\ % <--- Add desired seperator
    \makebox[.7cm][r]{\arrayij{data}{\thecolindex}{\therowindex}}% or use Fixed width
  }\par
}
\par}
For comparison, here are the margin delimiters\par
\noindent\hrulefill
\end{document}

在此处输入图片描述

答案2

您可以用于select equal part entry of这项工作。

\documentclass{article}
\usepackage{pgfplotstable}
\usepackage{longtable}
\pgfplotsset{compat=1.11}
\usepackage{filecontents}
\begin{filecontents*}{x_values.txt}
4.00E+00
5.00E+00
4.00E+00
5.00E+00
4.00E+00
6.00E+00
4.00E+00
1.00E+01
4.00E+00
4.00E+00
5.00E+00
4.00E+00
7.00E+00
4.00E+00
4.00E+00
5.00E+00
4.00E+00
5.00E+00
4.00E+00
6.00E+00
5.00E+00
4.00E+00
4.00E+00
6.00E+00
4.00E+00
5.00E+00
4.00E+00
4.00E+00
9.00E+00
4.00E+00
4.00E+00
5.00E+00
5.00E+00
4.00E+00
4.00E+00
4.00E+00
4.00E+00
5.00E+00
4.00E+00
4.00E+00
4.00E+00
4.00E+00
4.00E+00
4.00E+00
4.00E+00
4.00E+00
4.00E+00
4.00E+00
4.00E+00
6.00E+00
5.00E+00
4.00E+00
1.10E+01
5.00E+00
4.00E+00
4.00E+00
4.00E+00
6.00E+00
5.00E+00
4.00E+00
4.00E+00
4.00E+00
5.00E+00
4.00E+00
4.00E+00
4.00E+00
4.00E+00
4.00E+00
6.00E+00
5.00E+00
7.00E+00
5.00E+00
5.00E+00
4.00E+00
5.00E+00
4.00E+00
4.00E+00
5.00E+00
4.00E+00
4.00E+00
6.00E+00
4.00E+00
7.00E+00
4.00E+00
4.00E+00
8.00E+00
1.20E+01
4.00E+00
4.00E+00
8.00E+00
4.00E+00
4.00E+00
4.00E+00
4.00E+00
4.00E+00
6.00E+00
8.00E+00
4.00E+00
4.00E+00
4.00E+00
6.00E+00
5.00E+00
6.00E+00
5.00E+00
5.00E+00
9.00E+00
4.00E+00
4.00E+00
4.00E+00
4.00E+00
5.00E+00
5.00E+00
4.00E+00
8.00E+00
4.00E+00
1.50E+01
4.00E+00
4.00E+00
6.00E+00
4.00E+00
\end{filecontents*}
\pgfplotstableread[col sep = space]{x_values.txt}\mydata

\textheight=2cm
\begin{document}

\pgfplotstabletypeset[
    header=false,
    columns={0,0,0,0,0,0,0,0,0,0},
    display columns/0/.style={select equal part entry of={0}{10}},
    display columns/1/.style={select equal part entry of={1}{10}},
    display columns/2/.style={select equal part entry of={2}{10}},
    display columns/3/.style={select equal part entry of={3}{10}},
    display columns/4/.style={select equal part entry of={4}{10}},
    display columns/5/.style={select equal part entry of={5}{10}},
    display columns/6/.style={select equal part entry of={6}{10}},
    display columns/7/.style={select equal part entry of={7}{10}},
    display columns/8/.style={select equal part entry of={8}{10}},
    display columns/9/.style={select equal part entry of={9}{10}},
    every head row/.style={output empty row},
    begin table=\begin{longtable},
  end table=\end{longtable},
]{\mydata}

\end{document}

相关内容