0

I have a set of documents with lots of tables using the longtable package. I am looking for a way to force all tables full page width. I know that this can be done by setting this in the preambles:

\setlength\LTleft{0pt}
\setlength\LTright{0pt}

and then adding \extracolsep{\fill} to each table.

However is there a way to achieve the same effect without modifying each individual table? Perhaps by using renewenvironment to redefine longtable so that \extracolsep{\fill} is always used?

  • not really, you'd have to patch LT@array to modify the definition of \LT@bchunk to use fill rather than 0pt when setting \tabskip. simpler just to use \newcolumtype{Z}{@{\extracolsep{\fill}}} then use Z at the start of the longtable preamble argument (although forcing columns apart makes the table harder to read for no real gain) – David Carlisle May 19 '15 at 15:44
  • The problem is that I have no direct control over the column definitions (these documents are generated by an external tool). Any other option ? – Grodriguez May 19 '15 at 15:47
  • as I say my preferred option is not to do it and let the column separation be natural width, makes for easier reading, but if that isn't an option, use a patch command (eg from etoolbox) and change \tabskip\z@ to \tabskip\fill in \LT@array – David Carlisle May 19 '15 at 15:54
  • Thank you. Although I'll have to study that a bit before I understand your suggestion (I'm new to Latex :) – Grodriguez May 19 '15 at 16:13
2

enter image description here

\documentclass{article}

\usepackage{longtable,etoolbox}

\begin{document}

Nice
\begin{longtable}{cc}
\textbf{heading a}&\textbf{heading b}\\
1&2\\3&4\\5&6\\1&2\\3&4\\5&6
\end{longtable}

Horrible
{\setlength\LTleft{0pt}\setlength\LTright{0pt}
\begin{longtable}{@{\extracolsep{\fill}}cc@{}}
\textbf{heading a}&\textbf{heading b}\\
1&2\\3&4\\5&6\\1&2\\3&4\\5&6
\end{longtable}}

\makeatletter
\patchcmd\LT@array{\tabskip\z@}{\tabskip\fill}{\typeout{OK}}{\typeout{BAD}}
\setlength\LTleft{0pt}\setlength\LTright{0pt}
\makeatletter

Automatically Horrible
\begin{longtable}{cc}
\textbf{heading a}&\textbf{heading b}\\
1&2\\3&4\\5&6\\1&2\\3&4\\5&6
\end{longtable}

\end{document}
  • Very illustrative :) – Grodriguez May 19 '15 at 16:56

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.