3

I have a table with 1000 (variable, can be any) rows and 3 (fixed) columns. Each cell has a 10 digit number.

Displaying it in a single continuous stream of rows is not looking good and not maximal use of available print space.

I want it to be displayed from current point till end of current page. The remaining rows has to be folded and displayed till the bottom of the page and the process should continue till there is enough width available in the page. Subsequent rows should go into subsequent pages with same logic. The last set of rows should be evenly distributed from the top of the page so that the last row contains same number of columns as the first row.

Also the header of the columns need to be repeated in each of the instances of the columns. And if possible, the lines to be displayed between the rows and columns.

Thanks in Advance. Aravind

2
  • 1
    Welcome to TeX.SX! Probably it's simpler not to use a table.
    – egreg
    Commented Aug 2, 2016 at 13:06
  • Welcome to TeX SX! You can do that with a single long table, but part of the job will have to be done by hand. You can in a first step at which rows happen page breaks, and reorganise your data/code so that your obtain your three columns with a correct display.
    – Bernard
    Commented Aug 2, 2016 at 13:08

1 Answer 1

3

Here's a possibility:

\documentclass{article}
\usepackage{multicol}
\usepackage{capt-of}
\usepackage{siunitx}

\usepackage{lipsum} % just for the example

\newcommand{\entry}[3]{%
  \makebox[\columnwidth][s]{\num{#1}\hfil\num{#2}\hfil\num{#3}}\par
}
\newenvironment{pseudotabular}[1]% the argument is the caption
 {\setlength\columnsep{1cm}%
  \begin{multicols}{2}[\captionof{table}{#1}]
  \footnotesize
  \setlength\parindent{0pt}}
 {\end{multicols}}

\begin{document}

You can see the result in table~\ref{long}.

\lipsum[2]

\begin{pseudotabular}{A long table\label{long}}
\entry{1010101010}{2121212121}{3232323232}
\entry{1010101010}{2121212121}{3232323232}
\entry{1010101010}{2121212121}{3232323232}
\entry{1010101010}{2121212121}{3232323232}
...
\end{pseudotabular}

\end{document}

enter image description here

Another possibility is xtab, but tricking it into automatically getting balanced columns is almost impossible.

See Trick Supertabular into Multicols in new command and http://www.guitex.org/home/en/forum/5-tex-e-latex/26889-supertabular-e-twocolumn-riempimento-parziale-altezza-testo

\documentclass{article}
\usepackage{multicol,capt-of}
\usepackage{xtab}
\usepackage{siunitx}

\usepackage{lipsum} % just for the example

\newcommand{\entry}[3]{%
  \num{#1}&\num{#2}&\num{#3}\\\hline
}
\makeatletter
\def\mod@estimate@lineht{% 
  \ST@lineht=\arraystretch \baslineskp
%  \ST@lineht=.95\ST@lineht
  %\global\advance\ST@lineht by 1\p@ 
  \ST@stretchht\ST@lineht\advance\ST@stretchht-\baslineskp
  \ifdim\ST@stretchht<\z@\ST@stretchht\z@\fi
  \ST@trace\tw@{Average line height: \the\ST@lineht}% 
  \ST@trace\tw@{Stretched line height: \the\ST@stretchht}% 
}
\newenvironment{strictxtabular}
  {\let\estimate@lineht\mod@estimate@lineht\xtabular}
  {\endxtabular}
\newcommand{\TrickSupertabularIntoMulticols}{%
  \let\mcnewpage=\newpage
  \renewcommand\newpage{%
    \if@firstcolumn
      \hrule width\linewidth height0pt
      \columnbreak
    \else
      \mcnewpage
    \fi
  }%
}
\makeatother

\begin{document}

You can see the result in table~\ref{long}.

\lipsum[2]

\begin{multicols}{2}[\captionof{table}{A table\label{long}}]
\footnotesize\setlength{\tabcolsep}{2pt}
\TrickSupertabularIntoMulticols

\tablehead{%
  \multicolumn{1}{c}{\bfseries First} &
  \multicolumn{1}{c}{\bfseries Second} &
  \multicolumn{1}{c}{\bfseries Third} \\
}
\tabletail{\hline}
\begin{strictxtabular}{@{}|r|r|r|@{}}
\hline
\entry{1010101010}{2121212121}{3232323232}
\entry{1010101010}{2121212121}{3232323232}
\entry{1010101010}{2121212121}{3232323232}
\entry{1010101010}{2121212121}{3232323232}
\entry{1010101010}{2121212121}{3232323232}
\entry{1010101010}{2121212121}{3232323232}
\entry{1010101010}{2121212121}{3232323232}
\entry{1010101010}{2121212121}{3232323232}
\entry{1010101010}{2121212121}{3232323232}
\entry{1010101010}{2121212121}{3232323232}
...
\end{strictxtabular}
\end{multicols}

\end{document}

enter image description here

10
  • Thanks for the very useful reply. Is there a way to include the horizontal and vertical lines separating the rows and columns? Thanks in advance.
    – B Aravind
    Commented Aug 2, 2016 at 13:34
  • @BAravind Are you sure you want to make this like a worksheet window?
    – egreg
    Commented Aug 2, 2016 at 13:37
  • Also to repeat the header row after every folding and in each page. Thanks.
    – B Aravind
    Commented Aug 2, 2016 at 13:39
  • @BAravind For that you need xtab.
    – egreg
    Commented Aug 2, 2016 at 13:40
  • Not exactly. The lines need to be only within the three columns of same row. Adjacent folded rows ideally should not be connected. But I can take it for now if it is not possible or very complicated. But lines need be there to look like a table.
    – B Aravind
    Commented Aug 2, 2016 at 13:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .