9

Possible Duplicate:
How to fit landscape multi-page table to textwidth

I am trying to fit a longtable in a page with the following specifications:

\documentclass{article}
\usepackage[letterpaper]{geometry}
\geometry{tmargin=2cm,bmargin=2.5cm,lmargin=2.5cm,rmargin=2.7cm}
\usepackage{array}
\usepackage{longtable}
\begin{document}
\begin{longtable}{|c|>{\raggedright}p{4.5in}|p{0.85in}|}
\hline
\textbf{Week} & \textbf{Content} & \textbf{Assessments}\tabularnewline
\hline
\endfirsthead
\hline
\hline
\textbf{Week} & \textbf{Content} & \textbf{Assessments}\tabularnewline
\hline
\hline
\endhead
\hline
Week 1 & Unit 1
&HW, Q, T\tabularnewline
\hline
Week 2 & Unit 2
&HW, Q, T\tabularnewline
\hline
\end{longtable}
\end{document}

Note that to the naked eye, the table seems to be perfect, but I know that one can make the long table to span through the entire text width. I am looking for improvements and how to achieve the above effect (use of the text width.) If a similar question has been asked please redirect me.

1
  • 1
    I'm not sure what your question is: longtable always uses the full text width by default. There is (as always with latex tables) a tabcolsep at either side which you could remove by putting @{} at the start an end of the column specification. Or is your question that you want the p column widths to be automatic, like tabularx X columns in which case you might look at ltxtable or perhaps tabu Commented Jun 28, 2012 at 15:26

1 Answer 1

14

Page 7 of the user guide of the longtable package suggests issuing the commands

\setlength\LTleft{0pt}
\setlength\LTright{0pt}
...
\begin{longtable}{@{\extracolsep{\fill}}...} % replace "..." with actual column specifiers

to get a longtable that's automatically as wide as \textwidth. For the case of your table, you'd either issue the two \setlength commands in the preamble (to make them apply to all longtable environments) or localize them in a TeX group (so that they only apply to the longtable(s) within that group). Then, you'd use the command

\begin{longtable}{@{\extracolsep{\fill}}|c|>{\raggedright}p{4.5in}|p{0.85in}|}

to force this particular longtable to occupy the entire width of the text block.

Addendum: After posting this answer, I came across this question which deals, in essence, with the very same topic. I should have remembered this earlier, given that I was one of the persons who posted an answer...

3
  • If it is a duplicate, please close. :-)
    – azetina
    Commented Jun 28, 2012 at 19:10
  • ! Missing number, treated as zero..
    – barej
    Commented Feb 21 at 8:48
  • @barej - Sorry, but my mind-reading skills are quite poor. Please tell me more about the code that's giving rise to the error message. For sure, the following compilable example does not generate any warning or error messages. \documentclass{article} \usepackage{longtable} \begin{document} \setlength\LTleft{0pt} \setlength\LTright{0pt} \begin{longtable}{@{\extracolsep{\fill}}|c|>{\raggedright}p{3in}|p{1in}|} \hline a & b & c \\ \hline \end{longtable} \end{document} ,
    – Mico
    Commented Feb 21 at 9:53

Not the answer you're looking for? Browse other questions tagged .