I started with my answer at How do I create 6 parallel texts aligned by paragraph, with 3 texts on each page? as a baseline, but had to make a number of changes.
On the easier side, I don't have to worry about row entries of different heights for this OP's query. But on the negative side, I had to significantly rewrite code to handle 10 or more column entries (since #10
doesn't work). To that end, I didn't pass different column entries as arguments, but wrote my own tab parsing code, so that the row could be entered as if it were a tabular row.
I still used Herbert's code snippet for processing tabular tokens within a \whiledo
, and I added a snippet from Stephan Lehmke for starting the table on an even page number when in twoside
mode.
As a bonus feature, not only do I allow the code to be broken across left/right pages, but it can be broken vertically as well, for extra long tables. The syntax is \newtwopagetable
to initialize the process. Then, individual rows are added with \tenbyrow{}
where the argument is a &
-separated list of ten entries (it is minor rewrite for other column number entries). Finally, when all the data is entered in this fashion, you have two options:
\newtwopagetable{caption}
will output the whole table over two pages; or
\maketwopagetable[4]{caption}
\maketwopagetable[4]{caption}
will split the two-sided table into vertical pieces, as well, shown above as four rows on the first double page, and four rows on the second double page.
Here is the source code:
\documentclass[twoside]{article}% TABLE CLEARS TO EVEN PAGE
%\documentclass{article}% TABLE CLEARS TO NEXT PAGE
\usepackage{booktabs, array}
\usepackage{ifthen}
\usepackage{etoolbox}
\makeatletter%%%%%%%%%%% My own tab parsing code
\newcounter{TABcellindex@}
\newcommand\readTABrow[2]{%
\def\doneTABread{F}%
\def\postTAB{#2}%
\setcounter{TABcellindex@}{0}%
\whiledo{\equal{\doneTABread}{F}}{%
\stepcounter{TABcellindex@}%
\expandafter\processTAB\postTAB&\\%
\ifthenelse{\equal{\preTAB}{}}{%
\addtocounter{TABcellindex@}{-1}%
\def\doneTABread{T}%
}{%
\expandafter\protected@edef\csname #1\alph{TABcellindex@}\endcsname{%
\preTAB}%
}%
}%
% \#1TABcells GIVES HOW MANY TAB COLUMNS WERE PROCESSED
% \expandafter\xdef\csname #1TABcells\endcsname{\arabic{TABcellindex@}}%
}
\def\processTAB#1\\{%
\protected@edef\preTAB{#1}%
\protected@edef\postTAB{#2}%
}
\makeatother%%%%%%%%%%% END My own tab parsing code
\makeatletter%%%%%%%%%%% Herbert's tabular token code
\newcounter{tabindex}
\newtoks\@tabtoks
\newcommand\addtabtoks[1]{%
\@tabtoks\expandafter{\the\@tabtoks\stepcounter{tabindex}#1}}
\newcommand*\resettabtoks{\@tabtoks{}}
\newcommand*\synctabindex[1]{\setcounter{tabindex}{\value{#1}}}
\newcommand*\printtabtoks{\the\@tabtoks}
\makeatother%%%%%%%%%%% END Herbert's tabular token code
\makeatletter%%%%%%% Lehmke's \cleartoleftpage
\def\cleartoleftpage{\clearpage\if@twoside \ifodd\c@page
\hbox{}\newpage\if@twocolumn\hbox{}\newpage\fi\fi\fi}
\makeatother
\makeatother%%%%%%%% END Lehmke's \cleartoleftpage
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcounter{sptstartrow}
\newcounter{sptendrow}
\newcounter{entries}
\newcommand\newtwopagetable{%
\setcounter{sptendrow}{0}%
\setcounter{entries}{0}%
\cleartoleftpage%
}
\makeatletter
\newcommand\tenbyrow[1]{%
\stepcounter{entries}%
\readTABrow{entryX\roman{entries}X}{#1}%
}
\makeatother
\newcounter{index}
\newcommand\maketwopagetable[2][\theentries]{%
\setcounter{sptstartrow}{\thesptendrow}%
\ifthenelse{\thesptstartrow > 1}%
{\addtocounter{table}{-1}\def\conttext{, continued}}%
{\def\conttext{}}%
\addtocounter{sptendrow}{#1}%
\ifthenelse{\thesptendrow > \theentries}{\setcounter{sptendrow}{\theentries}}{}%
\clearpage
\setcounter{index}{\thesptstartrow}%
\synctabindex{index}
\resettabtoks%
\whiledo{\theindex < \thesptendrow}{%
\stepcounter{index}%
\addtabtoks{%
\csname entryX\roman{tabindex}Xa\endcsname &
\csname entryX\roman{tabindex}Xb\endcsname &
\csname entryX\roman{tabindex}Xc\endcsname &
\csname entryX\roman{tabindex}Xd\endcsname &
\csname entryX\roman{tabindex}Xe\endcsname
\\%
}%
}%
\begin{table}
\centering
\begin{tabular}{C{2cm} C{2cm} C{2cm} C{2cm} C{2cm}}
\toprule
\printtabtoks%
\bottomrule
\end{tabular}%
\caption{#2 (left half\conttext)}
\end{table}%
\addtocounter{table}{-1}%
\clearpage
\setcounter{index}{\thesptstartrow}%
\synctabindex{index}
\resettabtoks%
\whiledo{\theindex < \thesptendrow}{%
\stepcounter{index}%
\addtabtoks{%
\csname entryX\roman{tabindex}Xf\endcsname &
\csname entryX\roman{tabindex}Xg\endcsname &
\csname entryX\roman{tabindex}Xh\endcsname &
\csname entryX\roman{tabindex}Xi\endcsname &
\csname entryX\roman{tabindex}Xj\endcsname
\\%
}%
}%
\begin{table}
\centering
\begin{tabular}{C{2cm} C{2cm} C{2cm} C{2cm} C{2cm}}
\toprule
\printtabtoks%
\bottomrule
\end{tabular}%
\caption{#2 (right half\conttext)}
\end{table}%
}
\begin{document}
\newtwopagetable
\tenbyrow%
{~ & \textbf{Column 1} & \textbf{Column 2} & \textbf{Column 3} &
\textbf{Column 4} & \textbf{Column 5} & \textbf{Column 6} &
\textbf{Column 7} & \textbf{Column 8} & \textbf{Column 9}}
\tenbyrow%
{\textbf{Row 1} & Text (1,1) & Text (1,2) & Text (1,3) & Text (1,4)
& Text (1,5) & Text (1,6) & Text (1,7) & Text (1,8) & Text (1,9)}
\tenbyrow%
{\textbf{Row 2} & Text (2,1) & Text (2,2) & Text (2,3) & Text (2,4)
& Text (2,5) & Text (2,6) & Text (2,7) & Text (2,8) & Text (2,9)}
\tenbyrow%
{\textbf{Row 3} & Text (3,1) & Text (3,2) & Text (3,3) & Text (3,4)
& Text (3,5) & Text (3,6) & Text (3,7) & Text (3,8) & Text (3,9)}
\tenbyrow%
{\textbf{Row 4} & Text (4,1) & Text (4,2) & Text (4,3) & Text (4,4)
& Text (4,5) & Text (4,6) & Text (4,7) & Text (4,8) & Text (4,9)}
\tenbyrow%
{\textbf{Row 5} & Text (5,1) & Text (5,2) & Text (5,3) & Text (5,4)
& Text (5,5) & Text (5,6) & Text (5,7) & Text (5,8) & Text (5,9)}
\tenbyrow%
{\textbf{Row 6} & Text (6,1) & Text (6,2) & Text (6,3) & Text (6,4)
& Text (6,5) & Text (6,6) & Text (6,7) & Text (6,8) & Text (6,9)}
\tenbyrow%
{\textbf{Row 7} & Text (7,1) & Text (7,2) & Text (7,3) & Text (7,4)
& Text (7,5) & Text (7,6) & Text (7,7) & Text (7,8) & Text (7,9)}
\maketwopagetable{This is a table}
\newtwopagetable
\setcounter{entries}{8}% THIS IS TO FOOL LaTeX INTO THINKING I RE-ENTERED THE TABLE DATA
\maketwopagetable[4]{This is a vertically split table}
\maketwopagetable[4]{This is a vertically split table}
\end{document}
Here is the full table output on a double page:
While here is the table, split width and lengthwise, as output over the next four pages. Note that the (left/right half, continued)
commentary is provided by \maketwopagetable
, and is not part of the user's captioning argument.
I suppose you want your table to be exactly full text width. You can do that with the ltablex
package, which brings the longtable
functionalities (and syntax) of longtable
to tabularx
.
I took the liberty to place the caption above the table: if table captions are usually placed above tables, it is to spare readers from having to skim through pages to find what it's all about. Furthermore, in long tables (which are not floats, by the way, so the option [!ht]
is meaningless), the caption is called from within the table, in the first head code.
\documentclass[
10pt,
a5paper,
twoside
]{memoir}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[brazil]{babel}
\usepackage{ragged2e}
\usepackage{ltablex}
\keepXColumns
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.3pt}
\begin{document}
\frenchspacing
\setlength\extrarowheight{2pt}
\begin{tabularx}{\linewidth}{|>{\RaggedRight}p{3cm}|>{\arraybackslash}X|}
\caption{Formatação do texto}
\label{tab:table} \\
\hline
\endfirsthead
\multicolumn{2}{c}{\tablename~\thetable}: Formatação do texto (continued)\\
\hline
\endhead
\hline
\multicolumn{2}{r}{\footnotesize to be continued}
\endfoot
\hline
\endlastfoot
Tamanho da fonte & 10,5 para o texto incluindo os títulos das seções e subseções.
As citações com mais de três linhas as legendas das ilustrações
e tabelas, fonte 9,5.
\end{tabularx}
\end{document}
Best Answer
The
tabularx
package provides thetabularx
environment, which was designed for just this purpose.Here is a MWE:
Note that
tabularx
's first argument is the width of the table. In the above, I have chosen\textwidth
; when combined with theX
columntype (defined in thetabularx
package), it produces the 'fill-to-margin' effect that you want.