Graphics, Figures & Tables ⇒ Automatic table column wrapping
Automatic table column wrapping
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
Learn LaTeX easily with newest books:
The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis
The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more
LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis
Re: Automatic table column wrapping
the only one you can use is supertabular. When you are using it you can use the twocolumn-option.
regards
Marco
Re: Automatic table column wrapping
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
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
-
kaiserkarl13
- Posts: 707
- Joined: Tue Mar 25, 2008 5:02 pm
Re: Automatic table column wrapping
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?
-
kaiserkarl13
- Posts: 707
- Joined: Tue Mar 25, 2008 5:02 pm
Automatic table column wrapping
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
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}-
kaiserkarl13
- Posts: 707
- Joined: Tue Mar 25, 2008 5:02 pm
Re: Automatic table column wrapping
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!