6

I have 100 numbers and I want to print the numbers in multiple columns in one page like:

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

To be more precise, say, I want to print my data as {10 rows * 10 column} in one page. My data is stored in a .csv file. and the format in which data is stored is like:

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

. i have tried using pgfplotstable but i cant break the data into multiple columns. I am getting only single column.

the code i used is:

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

can anyone give any suggestion?

  • Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. – Symbol 1 Feb 13 '15 at 12:29
  • please show what your input csv looks like, is it already in 6 columns. You say you want the output in 6 columns but give no indication of the input, and show a table of numbers in 3 columns which does not appear to fit the question description at all. – David Carlisle Feb 13 '15 at 13:47
  • hi David, i have updated my query. please have a look. thanks – Sakil Chowdhury Feb 13 '15 at 14:14
2

The readarray package expects space separated data (I need to change that feature). But since your data in the file is provided single column, there are no commas in the csv file, and space/line separation is sufficient to parse the data.

EDITED to center the "table".

This uses an input file Book1.csv of the format specified:

1
2
3
...
98
99
100

Here is the 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}

The line with \arrayij can use a separator or a box for the data cell; I use a box.

enter image description here


If one didn't want the extra vertical space of the center environment...

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

enter image description here

  • u are an absolute genius! I have been looking for these for the past 5 hours. gone through many websites and documents! thank u so much. but i last thing, i just want to print integers rather than the exponential forms. how can i do that? – Sakil Chowdhury Feb 13 '15 at 14:38
  • @SakilChowdhury I don't know how to automatically convert exponential to integer form (in LaTeX), but if you can tell me with absolute certainty that it will always be e8.2 format, for example, I could perhaps write a quick conversion routine. Is there the possibility for negative data? – Steven B. Segletes Feb 13 '15 at 14:47
  • nope. the data will be always positive and integer. thank u so mcuh @steven – Sakil Chowdhury Feb 13 '15 at 14:50
  • @SakilChowdhury But will it always be x.xxE+xx? as opposed to x.xxxxE+xx... – Steven B. Segletes Feb 13 '15 at 14:51
  • yap. u are right. @steven – Sakil Chowdhury Feb 13 '15 at 14:54
2

You can use select equal part entry of for this job.

\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}
  • hi, thank u so much for your answer. i have updated the question again to clarify my prob. please have a look. thank u so much. – Sakil Chowdhury Feb 13 '15 at 14:09
  • hi, thank u for replying. actually, i am trying to modify the code but i cant make it work as i would like to. i have changed the code as : ` columns={0}, %i have only one column in my csv file display columns/0/.style={select equal part entry of={0}}, ` but this is not working. can u plz suggest. – Sakil Chowdhury Feb 13 '15 at 14:25
  • please see the question. i have added the data there just now. although i could not put all of them. I have 10000 points in my csv file. and I want to print first 100 of them in my report. – Sakil Chowdhury Feb 13 '15 at 14:31
  • @SakilChowdhury Please see the update. – user11232 Feb 13 '15 at 14:59
  • thank u so much. I have got what i was looking for. thank u so much for your time and help. really appreciate it. :) – Sakil Chowdhury Feb 13 '15 at 15:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.