2

I have create a multi-page table. Using tabularx, my attempt is as follows:

\documentclass[a4paper,preprint,aps,unsortedaddress]{revtex4}
\usepackage[top=2.5cm,bottom=2.5cm,left=3.5cm,right=2.5cm]{geometry}
\usepackage{ltablex}
\usepackage{longtable,booktabs}

\ifdefined\mc
\renewcommand{\mc}{\multicolumn}
\else
\newcommand{\mc}{\multicolumn}
\fi

\begin{document}

\begin{tabularx}{\linewidth}{lr@{--}p{1.3cm}>{\centering\arraybackslash}p{2.6cm}p{1.25cm}p{1.25cm}p{1.25cm}p{1.25cm}p{2.1cm}p{0.7cm}}
\caption{Table} \\ \hline \hline
\endfirsthead
\mc{8}{c}{\tablename\ \thetable\ -- \emph{Continued from previous page}} \\ \hline
aaa & \mc{2}{c}{bbb--ccc} & ddd & eee & fff & ggg & hhh & iii & jjj \\ \hline
\endhead
\hline \mc{8}{r}{\emph{ Continued on next page }} \\
\endfoot
\hline \hline
\endlastfoot
aaa & \mc{2}{c}{bbb--ccc} & ddd & eee & fff & ggg & hhh & iii & jjj \\
aaa & bbb & ccc & ddd & eee & fff & ggg & hhh & iii & jjj \\
aaa & bbb & ccc & ddd & eee & fff & ggg & hhh & iii & jjj \\
aaa & bbb & ccc & ddd & eee & fff & ggg & hhh & iii & jjj
\end{tabularx}

\end{document}

which does not contain a X column. I would like to obtain a correct multi-page table utilizing the {lr@{--}p{1.3cm}>{\centering\arraybackslash}p{2.6cm}p{1.25cm}p{1.25cm}p{1.25cm}p{1.25cm}p{2.1cm}p{0.7cm}} format. Could you please help me how to rewrite this code to obtain a correct table?

  • Your requirements appear to be mutually exclusive. E.g., the width of the current tabularx environment is less than \textwidth. By switching to a setup with one or more columns of type X, the table's width will increase to \textwidth. However, that seems to be expressly forbidden, since you've also written that "the output format of the table cannot change". Or is the width of a table not part of its format? What gives? – Mico Feb 12 at 18:21
  • Could we chat on this problem? – Roloka Feb 12 at 18:23
  • 1
    Please edit your posting to clarify your objectives. – Mico Feb 12 at 18:24
  • Edited. Could you please check it? – Roloka Feb 12 at 18:33
  • 1
    Since you seem to have hit on a format that's to your liking, and since the width is less than \textwidth, why don't you just define a longtable? – Mico Feb 12 at 18:36
3

Since the table's width is slightly less than \textwidth, there seems to be no need for the tabularx-related overhead. Instead, just use a longtable to typeset the material.

enter image description here

\documentclass[a4paper,preprint,aps,
               unsortedaddress]{revtex4}
\usepackage[top=2.5cm,bottom=2.5cm,
            left=3.5cm,right=2.5cm,
            showframe]{geometry}
\usepackage{longtable,array,booktabs}
\ifdefined\mc
   \renewcommand{\mc}{\multicolumn}
\else
   \newcommand{\mc}{\multicolumn}
\fi

\begin{document} 
\begin{longtable}{ l r @{--} p{1.3cm} >{\centering}p{2.6cm} 
                   *{5}{p{1.25cm}} p{2.1cm} p{0.7cm} }               
%% headers and footers

\caption{Table} \\ 
\hline\hline
\endfirsthead

\mc{10}{c}{\tablename\ \thetable\ -- \emph{Continued from previous page}} \\ 
\hline
aaa & \mc{2}{c}{bbb--ccc} & ddd & eee & fff & ggg & hhh & iii & jjj \\
\hline
\endhead

\hline
\mc{10}{r}{\emph{Continued on next page}} \\
\endfoot

\hline\hline
\endlastfoot

%% body of table

aaa & \mc{2}{c}{bbb--ccc} & ddd & eee & fff & ggg & hhh & iii & jjj \\
aaa & bbb & ccc & ddd & eee & fff & ggg & hhh & iii & jjj \\
aaa & bbb & ccc & ddd & eee & fff & ggg & hhh & iii & jjj \\
aaa & bbb & ccc & ddd & eee & fff & ggg & hhh & iii & jjj \\

\end{longtable}
\end{document}
  • Thank you very much! Just two quick question: how to reduce left and right margins around the table? I tried to use \setlength\LTleft{-3.0cm} and \setlength\LTright{-2.5cm} but they are not working. :( – Roloka Feb 12 at 19:03
  • Please clarify what you mean by "reduce left and right margins around the table". For sure, the longtable fits (just) inside the textblock. – Mico Feb 12 at 19:15
  • \usepackage[top=2.5cm,bottom=2.5cm, left=3.5cm,right=2.5cm, showframe]{geometry} defines 3.5 and 2.5 cm margins on the left and right sides, respectively. I would like to use 0.5 and 0.5 cm for them, but only around the table (my tables are too wide). – Roloka Feb 12 at 19:17
  • @Roloka - I don't understand: the total width of the longtable is less than \textwidth. By the way, rather than make the table even wider, I'd reduce the amount of intercolumn whitespace. – Mico Feb 12 at 19:47
  • @Roloka -- Do you want me to delete this answer as it evidently doesn't address your real, though unstated, formatting requirments? – Mico Feb 12 at 19:49

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.