Graphics, Figures & Tables ⇒ Automatic table column wrapping
Automatic table column wrapping
All,
Let's say that I have a table with 40 rows x 2 columns and the columns are narrow. Is there any package that would look at the table and determine that it could do 2 sets of 20 rows x 2 columns. In effect, I would want it to do:
Col-A Col-B | Col-A Col-B
vala1 valb1 | vala21 valb21
vala2 valb2 | vala22 valb22
... ... | ... ...
vala20 valb20 | vala40 valb40
Thanks
James
Let's say that I have a table with 40 rows x 2 columns and the columns are narrow. Is there any package that would look at the table and determine that it could do 2 sets of 20 rows x 2 columns. In effect, I would want it to do:
Col-A Col-B | Col-A Col-B
vala1 valb1 | vala21 valb21
vala2 valb2 | vala22 valb22
... ... | ... ...
vala20 valb20 | vala40 valb40
Thanks
James
NEW: TikZ book now 40% off at Amazon.com for a short time.
Re: Automatic table column wrapping
Hello,
the only one you can use is supertabular. When you are using it you can use the twocolumn-option.
regards
Marco
the only one you can use is supertabular. When you are using it you can use the twocolumn-option.
regards
Marco
i am German. I can not use difficult words. 

Re: Automatic table column wrapping
Hi... I gave this a try two different ways.
I tried \twocolumn before and \onecolumn after the table, but it didn't have any effect. Just to test, I set center before the table. The table was set down the middle of the page.
I also tried it using \begin{multicols}{2} but the table is set down the left column of the page, with the right column blank, and the the left column on the next page. I can tell that the table is centered in the column.
Does anyone have any ideas?
Thanks in advance,
James
I tried \twocolumn before and \onecolumn after the table, but it didn't have any effect. Just to test, I set center before the table. The table was set down the middle of the page.
I also tried it using \begin{multicols}{2} but the table is set down the left column of the page, with the right column blank, and the the left column on the next page. I can tell that the table is centered in the column.
Does anyone have any ideas?
Thanks in advance,
James
Automatic table column wrapping
Hello,
here an example that works:
regards
Marco
here an example that works:
Code: Select all
\documentclass[a4paper,12pt]{scrreprt}
\usepackage{array,supertabular,ragged2e,multicol}
\begin{document}
\twocolumn
\tablefirsthead{%
\hline Col-A & Col-B \\\hline}
\tablehead{%
\hline
\multicolumn{2}{|l|}{\small\sl continued from previous page}\\\hline
Col-A & Col-B \\\hline}
\tabletail{%
\hline\multicolumn{2}{|r|}{\small\sl continued on next page}\\\hline}
\tablelasttail{\hline}
\bottomcaption{This table is split}
\begin{supertabular}{|c|c|}
20 & 22 \\\hline 20 & 22 \\\hline 20 & 22 \\\hline 20 & 22 \\\hline 20 & 22 \\\hline 20 & 22 \\\hline 20 & 22 \\\hline 20 & 22 \\\hline
20 & 22 \\\hline 20 & 22 \\\hline 20 & 22 \\\hline 20 & 22 \\\hline 20 & 22 \\\hline 20 & 22 \\\hline 20 & 22 \\\hline 20 & 22 \\\hline
20 & 22 \\\hline 20 & 22 \\\hline 20 & 22 \\\hline 20 & 22 \\\hline 20 & 22 \\\hline 20 & 22 \\\hline 20 & 22 \\\hline 20 & 22 \\\hline
20 & 22 \\\hline 20 & 22 \\\hline 20 & 22 \\\hline 20 & 22 \\\hline 20 & 22 \\\hline 20 & 22 \\\hline 20 & 22 \\\hline 20 & 22 \\\hline
20 & 22 \\\hline 20 & 22 \\\hline 20 & 22 \\\hline 20 & 22 \\\hline 20 & 22 \\\hline 20 & 22 \\\hline 20 & 22 \\\hline 20 & 22 \\\hline
20 & 22 \\\hline 20 & 22 \\\hline 20 & 22 \\\hline 20 & 22 \\\hline 20 & 22 \\\hline 20 & 22 \\\hline 20 & 22 \\\hline 20 & 22 \\\hline
20 & 22 \\\hline 20 & 22 \\\hline 20 & 22 \\\hline 20 & 22 \\\hline 20 & 22 \\\hline 20 & 22 \\\hline 20 & 22 \\\hline 20 & 22 \\\hline
20 & 22 \\\hline 20 & 22 \\\hline 20 & 22 \\\hline 20 & 22 \\\hline 20 & 22 \\\hline 20 & 22 \\\hline 20 & 22 \\\hline 20 & 22 \\\hline
\end{supertabular}
\end{document}
Marco
i am German. I can not use difficult words. 

-
- Posts: 707
- Joined: Tue Mar 25, 2008 5:02 pm
Re: Automatic table column wrapping
The example provided only works if the table is the first thing on a page. Otherwise, supertabular realizes it has way too many rows to typeset on one page and starts a new one (even though that's unnecessary due to the second column!).
It also doesn't work inside the multicol package's multicols environment (you get two tables on two pages, with nothing in the second column).
I'm trying to do the same thing as the initial poster---that is, create a table that is created (and numbered) as a single table but is typeset as two super-columns, each containing its own version of the original table.
My original thought was to have two running counters (one for the right column and one for the left), with the start of the right column counter defined like so:
\@ifundefined{r@lastlstruct}{}{\setcounter{rstructure}{\ref{lastlstruct}}}%
However, this breaks if I use the calc package, AND requires me to manually create the columns (which makes modifying the table very difficult).
Any ideas?
It also doesn't work inside the multicol package's multicols environment (you get two tables on two pages, with nothing in the second column).
I'm trying to do the same thing as the initial poster---that is, create a table that is created (and numbered) as a single table but is typeset as two super-columns, each containing its own version of the original table.
My original thought was to have two running counters (one for the right column and one for the left), with the start of the right column counter defined like so:
\@ifundefined{r@lastlstruct}{}{\setcounter{rstructure}{\ref{lastlstruct}}}%
However, this breaks if I use the calc package, AND requires me to manually create the columns (which makes modifying the table very difficult).
Any ideas?
-
- Posts: 707
- Joined: Tue Mar 25, 2008 5:02 pm
Automatic table column wrapping
I wanted to see if anyone has a solution to the posted problem, as I'm still trying to figure this out.
The desired function is to generate a table that is half the width of the printed table, with the second half of the table printed in the second column. In short, typing something like
results in the table
a a a a A A A A
b b b b B B B B
c c c c C C C C
(assuming, of course, that the bottom of the page was only three lines away from the start of the table...).
The desired function is to generate a table that is half the width of the printed table, with the second half of the table printed in the second column. In short, typing something like
Code: Select all
\begin{splittabular}{l l l l}
a & a & a & a \\
b & b & b & b \\
c & c & c & c \\
A & A & A & A \\
B & B & B & B \\
C & C & C & C \\
\end{splittabular}
a a a a A A A A
b b b b B B B B
c c c c C C C C
(assuming, of course, that the bottom of the page was only three lines away from the start of the table...).
Automatic table column wrapping
Here is a custom implementation, but perhaps there is a package that already implements this:
Code: Select all
\documentclass{article}
\usepackage{environ}
\usepackage{etoolbox}
\DeclareListParser{\ProcessTableRows}{\\}
\newcount\RowCount
\newcount\RowIndex
\NewEnviron{splittabular}[1]{%
\RowCount=0 %
\def\do##1{\advance\RowCount by 1 }%
\expandafter\ProcessTableRows\expandafter{\BODY}%
\divide\RowCount by 2 %
\RowIndex=0 %
\def\do##1{%
\ifnum\RowIndex<\RowCount
\csdef{Row-\number\RowIndex}{##1}%
\else
\eappto\AllRows{\csexpandonce{Row-\number\numexpr\RowIndex-\RowCount}\unexpanded{&##1\tabularnewline}}%
\fi
\advance\RowIndex by 1 %
}%
\expandafter\ProcessTableRows\expandafter{\BODY}%
\tabular{#1#1}%
\AllRows
\endtabular
}
\begin{document}
\begin{splittabular}{l l l l}
a & a & a & a \\
b & b & b & b \\
c & c & c & c \\
A & A & A & A \\
B & B & B & B \\
C & C & C & C \\
\end{splittabular}
\end{document}
-
- Posts: 707
- Joined: Tue Mar 25, 2008 5:02 pm
Re: Automatic table column wrapping
phi, thank you for posting this---extraordinary helpful. I managed to tweak it to place vertical lines down the center, too.
I'm going to see if I can make a variant on this that allows running lists of automatically numbered table cells, e.g.,
1 blah blah 4 blah blah
2 blah blah 5 blah blah
3 blah blah 6 blah blah
Entered as:
\countem & blah & blah \\
\countem & blah & blah \\
\countem & blah & blah \\
\countem & blah & blah \\
\countem & blah & blah \\
\countem & blah & blah \\
I'll also have to do some work to get \hline and/or \cline to work. Perhaps this isn't possible, but now that I know there are some interesting add-ons that may make it at least hypothetically possible I have to try.
Thanks again!
I'm going to see if I can make a variant on this that allows running lists of automatically numbered table cells, e.g.,
1 blah blah 4 blah blah
2 blah blah 5 blah blah
3 blah blah 6 blah blah
Entered as:
\countem & blah & blah \\
\countem & blah & blah \\
\countem & blah & blah \\
\countem & blah & blah \\
\countem & blah & blah \\
\countem & blah & blah \\
I'll also have to do some work to get \hline and/or \cline to work. Perhaps this isn't possible, but now that I know there are some interesting add-ons that may make it at least hypothetically possible I have to try.
Thanks again!