5

I am using the tabularx environment since it the X component of the columns is very useful and necessary for the tables I want to produce. However, a single one of my tables is longer that a page, and I would like it to break over the page, without any of my other tabularx tables breaking over the page. Is there a way of doing this? I have found the ltablex package that will do the job of breaking the tables, but I don't wish it to apply to all my tables. Is it some way of using \renewenvironment?

\documentclass{article} 
\usepackage{fullpage} 
\usepackage{tabularx} 
\usepackage{ltablex}    % This is the package I would like to apply to a single table
\usepackage{bigstrut} 
\begin{document} 

\begin{center}
\begin{tabularx}{\textwidth}{|l X l|}
\hline
& \textbf{HEADING} & \textbf{HEADING} \bigstrut \tabularnewline
\hline
\textbf{Number} & \textbf{WORDS} & \textbf{WORD} \bigstrut[t] \tabularnewline
& TEXT & \tabularnewline
\textbf{Number} & \textbf{WORDS} & \textbf{WORD} \tabularnewline
& TEXT & \tabularnewline
\textbf{Number} & \textbf{WORDS} & \textbf{WORD} \tabularnewline
& TEXT & \tabularnewline
\textbf{Number} & \textbf{WORDS} & \textbf{WORD} \tabularnewline
& TEXT & \tabularnewline
\textbf{Number} & \textbf{WORDS} & \textbf{WORD} \tabularnewline
& TEXT & \tabularnewline
\textbf{Number} & \textbf{WORDS} & \textbf{WORD} \tabularnewline
& TEXT & \tabularnewline
\textbf{Number} & \textbf{WORDS} & \textbf{WORD} \tabularnewline
& TEXT & \tabularnewline
\textbf{Number} & \textbf{WORDS} & \textbf{WORD} \bigstrut[t] \tabularnewline
& TEXT & \tabularnewline
\end{tabularx}
\end{center}
\end{document}

This has enough lines of text in it to go over the page length. I was thinking along the lines bringing the ltablex package down into the environment, and I need to retain the X functionality of the tabularx environment

hfmaciver
  • 165
  • Please add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. – jub0bs Jan 10 '14 at 15:03
  • 1
    Instead of loading the ltablex package, you could consider loading the ltxtable package. An advantage of using the latter package is that it doesn't modify the tabularx environment. (The ltxtable package provides hooks for extending the longtable environment so that it accepts columns of type X a la tabularx.) – Mico Jan 10 '14 at 15:06
  • 1
    @Mico I was going to say that:-) Or of course if you don't need the X feature in the long table use longtable – David Carlisle Jan 10 '14 at 15:07
  • @Mico I want to modify the tabularx environment, and I want to use it, especially since I have many tables that work fine, and have already been coded, that I don't want to redo. – hfmaciver Jan 10 '14 at 15:48
  • @Jubobs, I don't have a working example here, since I was asking for tables in general. I want to know how to make changes to how a single table operates that doesn't affect all of them. – hfmaciver Jan 10 '14 at 15:49
  • I understand, but a minimal working example is good to get potentially helpful people started on your problem. Otherwise, they have to recreate the situation themselves, which takes time and energy they could spend on other issues. – jub0bs Jan 10 '14 at 15:50
  • @hfmaciver - I'm not sure I understand your argument. In your posting, you mention the fact that loading the ltablex package modifies all tabularx environments, and that this is something you don't want to see happen. Having tables span more than one page is not something that can be automated entirely; some judgment, common sense, and attention to detail are needed. If you load the ltxtable package, you can work specifically on the table that spans more than one page while leaving the other tabularx environments unaffected -- which, if I understand you correctly, is what you want. – Mico Jan 10 '14 at 16:00
  • Please also note, just in case you haven't done so already, that the ltablex package (which you mention in your posting) and the ltxtable package (which I mentioned in an earlier comment) are not the same. Have you given the ltxtable package and method a try? – Mico Jan 13 '14 at 10:15
  • Sorry, I'm relatively new here, and didn't see the lower comments. I'm not sure I understand how the ltxtable works, is there and example about? – hfmaciver Jan 13 '14 at 10:25
  • There are quite a few postings on this site that show to use the ltxtable package. See, for instance, How to set the width of column in longtable method? and Textwidth longtable with centered headers. – Mico Jan 13 '14 at 12:00
  • Are there any news here? – Johannes_B Jan 18 '15 at 20:33

1 Answers1

1

Here's how to do this using ltxtable:

  1. Table goes in a separate file; environment longtable; with tabularx-style X column specifiers where needed.
  2. Insert the table using \LTXtable{<target-width>}{<file>}, setting the desired width and choosing the appropriate file which contains the longtable environment.

One note: the center environment adds additional vertical space which might not be desired in some usage. It might be better to use {\centering <content to be centered>} in some situations (usually inside figure/table environments), which does not insert extra vertical space. I've shown the \centering method here, but it's up to you to decide based on how this is included in your document.

\RequirePackage{filecontents}
\begin{filecontents*}{mytable.tex}
\begin{longtable}{|l X l|}
\hline
& \textbf{HEADING} & \textbf{HEADING} \bigstrut \tabularnewline
\hline
\textbf{Number} & \textbf{WORDS} & \textbf{WORD} \bigstrut[t] \tabularnewline
& TEXT & \tabularnewline
\textbf{Number} & \textbf{WORDS} & \textbf{WORD} \tabularnewline
& TEXT & \tabularnewline
\textbf{Number} & \textbf{WORDS} & \textbf{WORD} \tabularnewline
& TEXT & \tabularnewline
\textbf{Number} & \textbf{WORDS} & \textbf{WORD} \tabularnewline
& TEXT & \tabularnewline
\textbf{Number} & \textbf{WORDS} & \textbf{WORD} \tabularnewline
& TEXT & \tabularnewline
\textbf{Number} & \textbf{WORDS} & \textbf{WORD} \tabularnewline
& TEXT & \tabularnewline
\textbf{Number} & \textbf{WORDS} & \textbf{WORD} \tabularnewline
& TEXT & \tabularnewline
\textbf{Number} & \textbf{WORDS} & \textbf{WORD} \bigstrut[t] \tabularnewline
& TEXT & \tabularnewline
\end{longtable}
\end{filecontents*}

\documentclass{article} 
\usepackage{fullpage} 
\usepackage{tabularx} 
\usepackage{ltxtable}    % This is the package I would like to apply to a single table
\usepackage{bigstrut} 
\begin{document} 

{\centering
  \LTXtable{\textwidth}{mytable}
}
\end{document}

enter image description here

Paul Gessler
  • 29,607