Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have several tables in my document that are just a bit too small to fill the entire page, vertically.

I'd like to stretch the table, either by adding empty lines at the bottom, or by stretching the lineskip, so that the table fills the text area.

How would I go about this?

\documentclass{scrbook} % because that is what I use

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage{tabularx}

\usepackage{showframe}
\usepackage{lipsum}

\begin{document}

\begin{table*}
\begin{tabularx}{\linewidth}{|X|X|}
\hline
\textbf{Column A} & \textbf{Column B}\\
\hline
\lipsum[1] & \lipsum[2] \\
\hline
\end{tabularx}
\end{table*}

\end{document}

I want the red-marked whitespace to disappear, i.e. the table borders to match the textarea borders.

enter image description here

Note that this is contrived. In the real document, this is about sidewaystable - making the non-textarea height much more disruptive for the overall layout, and removing the option of simply having surrounding text take up the whitespace.

share|improve this question
1  
Take a look at package tabularht. It deals with the spacing between rows, however the line spacing inside a table cell is not affected. –  Heiko Oberdiek Nov 16 '12 at 9:02
    
which is better of course depends whether you have enough table rows to add the space between, in an example like the MWE where ether only two rows adding space within the row makes more sense, You could do both of course. I don't understand the "package" comment you can stick the definition in ugg.sty and use \usepackage{ugg} as an alternative to putting it in the preamble, it is the same thing. –  David Carlisle Nov 16 '12 at 9:26
    
@DavidCarlisle: I'm a programmer. It's the decision between using an include from "the standard library", or adding copypasted code to my project. No offense intended, it's a matter of personal preference. (Besides, Heiko's package doesn't work properly in my real document, so "better" is still open to discussion. ;-) ) –  DevSolar Nov 16 '12 at 10:41
    
yes but you're using tabularx and that's just some answer I posted to comp.text.tex one day so the difference doesn't seem so great to me:-) –  David Carlisle Nov 16 '12 at 10:54
    
@HeikoOberdiek: I had some trouble with tabularht. Apparently the vertical space of the caption is not taken into account; i.e., a tabularht with a height of \textheight and a caption extends below the text area by exactly the height of the caption. –  DevSolar Nov 17 '12 at 13:57
show 3 more comments

4 Answers 4

up vote 4 down vote accepted

A solution, where the caption is put inside the tables (example tables taken from the answers of David Carlisle and DevSolar):

\documentclass[captions=tableheading]{scrbook}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage{tabularx}
\usepackage{rotating}

\usepackage[vlines]{tabularht}

\usepackage{showframe}
\usepackage{lipsum}   

\newdimen\orgtextwidth
\setlength{\orgtextwidth}{\textwidth}

\begin{document}

\makeatletter

\begin{table*}
\begin{tabularhtx}{\textheight}{\linewidth}{|X|X|}
\noalign{%
  \caption{This is an example}%
}
\hline
\interrowfill
\textbf{Column A} & \textbf{Column B}\\
\interrowfill
\hline
\interrowfill
\lipsum[2] & \lipsum[2]\\
\interrowfill
\hline
\end{tabularhtx}
\end{table*}

\begin{table*}
\centering
\begin{tabularht}{\textheight}{|l|}
\multicolumn{1}{@{}c@{}}{%
  \hbox to 0pt{%
    \hss
    \centerline{%
      \parbox{\linewidth}{%
       \caption{This is an example}%
      }%
    }%  
    \hss
  }%
}\\ 
\hline
\interrowfill
\textbf{Col.}\\
\interrowfill  
\hline
\interrowfill
abc\\
\interrowfill
def\\
\interrowfill
ghi\\
\interrowfill
\hline
\end{tabularht}
\end{table*}   

\clearpage

\begin{sidewaystable*}
\begin{tabularhtx}{\orgtextwidth}{\linewidth}{|X|X|}
\hline
\noalign{\captionabove{This is an example}}
\hline
\interrowfill
\textbf{Column A} & \textbf{Column B}\\
\interrowfill
\hline
\interrowfill
\lipsum[2] & \lipsum[2]\\
\interrowfill
\hline
\end{tabularhtx}
\end{sidewaystable*}
\end{document}

Remarks:

  • The horizontal position inside \noalign is the left border of the tabular. Because the width of the tabular is not known here, a proper centering is only possible, if the table spans the full width.

  • KOMA-Script option captions=tableheadings added to get the correct spacing for the table captions.

  • Inside sidewaystable* \captionabove is used, because KOMA-Script fails to see that this is also a table.

share|improve this answer
    
Much superior (due to less macro magic). Thank you very much! –  DevSolar Nov 22 '12 at 8:41
add comment

or the exact opposite of the comment I see @Heiko just made, this affects cells but not table rows.

enter image description here

\documentclass{scrbook} % because that is what I use

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage{tabularx}

\makeatletter
\def\ugg#1{{%
\sbox{0}{\tx}
\dimen0\dimexpr\ht0+\dp0
\sbox{0}{\advance\normalbaselineskip1pt \tx}
\count@\strip@pt\dimexpr\ht0+\dp0 - \dimen0 \relax\relax
\dimen@\dimexpr\textheight-\ht0-\dp0\relax
\divide\dimen@ \count@
\advance\normalbaselineskip\dimen@ \tx
}}
\makeatother

\usepackage{showframe}
\usepackage{lipsum}

\begin{document}

\def\tx{%
\begin{tabularx}{\linewidth}{|X|X|}
\hline
\textbf{Column A} & \textbf{Column B}\\
\hline
\lipsum[1] & \lipsum[2] \\
\hline
\end{tabularx}}

\begin{table*}
\ugg{\tx}
\end{table*}

\end{document}
share|improve this answer
add comment

Heiko's comment on tabularht set me on the right path, and egreg helped me with figuring out how to take caption height into account. This is the complete solution. (Perhaps something to consider for includion in tabularht?)

\documentclass{scrbook}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage{tabularx}
\usepackage{rotating}

% These are the packages required by the solution
\usepackage[vlines]{tabularht}
\usepackage{calc}

% The sidewaystable environment screws up \textwidth,
% so we have to store its value beforehand.
\newlength{\SidewaysTextHeight}
\setlength{\SidewaysTextHeight}{\textwidth}

% Full-page height minus the vertical size of the caption
\newlength{\TabularhtHeight}

\makeatletter
% \captionht - typeset a caption and simultaneously set \TabularhtHeight
\newcommand{\captionht}[2][]{%
    \stepcounter{table}%
    \setbox\z@=\vbox{\@makecaption\fnum@table{#2}}%
    \addtocounter{table}{-1}%
    \setlength{\TabularhtHeight}{\textheight-\ht\z@-\lineskip}%
    \if\relax\detokenize{#1}\relax
        \caption{#2}%
    \else
        \caption[#1]{#2}%
    \fi
}

% \captionwd - as \captionht, but for sidewaystable
\newcommand{\captionwd}[2][]{%
    \stepcounter{table}%
    \setbox\z@=\vbox{\@makecaption\fnum@table{#2}}%
    \addtocounter{table}{-1}%
    \setlength{\TabularhtHeight}{\SidewaysTextHeight-\ht\z@-\lineskip}%
    \if\relax\detokenize{#1}\relax
        \caption{#2}%
    \else
        \caption[#1]{#2}%
    \fi
}
\makeatother

\usepackage{showframe}
\usepackage{lipsum}

\begin{document}

\begin{table*}
\captionht{Caption} % \captionht for table
\begin{tabularhtx}{\TabularhtHeight}{\linewidth}{|X|X|}
\hline
\interrowfill
\textbf{Column A} & \textbf{Column B}\\
\interrowfill
\hline
\interrowfill
\lipsum[2] & \lipsum[2]\\
\interrowfill
\hline
\end{tabularhtx}
\end{table*}

\clearpage

\begin{sidewaystable*}
\captionwd{Caption} % \captionwd for sidewaystable
\begin{tabularhtx}{\TabularhtHeight}{\linewidth}{|X|X|}
\hline
\interrowfill
\textbf{Column A} & \textbf{Column B}\\
\interrowfill
\hline
\interrowfill
\lipsum[2] & \lipsum[2]\\
\interrowfill
\hline
\end{tabularhtx}
\end{sidewaystable*}

\end{document}

You might note that the sidewaystable does not fit the textarea exactly. I'd welcome any hints as to why that is the case.

Edit: Contacted the rotating maintainer about the layout issue. Will update here if I recieve feedback.

share|improve this answer
    
I have analyzed the rotating bug with the horizontal displacement. The package wrongly assumes that minipage with c puts the middle line to the base line, but minipage uses \vcenter here and that means the middle line is put on the math axis. I have made a bug report and suggested a fix. –  Heiko Oberdiek Nov 22 '12 at 1:11
add comment

I wrote this code trying to achieve tabularx fill the page vertically. Comments? In which circumstances this may fail? If the space to fill is less than one line the final \hline will not be drawn!

I did put a \framebox to explicitly see the filled space.

\documentclass{article}
\usepackage{tabularx}
\usepackage{zref-savepos}
\usepackage{calc}
\usepackage{geometry}
\newlength{\Start}
\newlength{\End}
\newlength{\Diff}
\newbox{\ParBox}
\geometry{paperheight=300pt,vmargin={0pt,0cm},hmargin{0cm,0cm},footskip=0pt,headsep=0pt,headheight=0pt}
\begin{document}
\setlength{\parindent}{0cm}
\setlength{\Start}{\zposy{start}sp}%
\setlength{\End}{\zposy{end}sp}%
\setlength{\Diff}{\Start-\End}
\savebox{\ParBox}{\parbox[t][\Diff]{2cm}{\mbox{}}}%
\begin{tabularx}{10cm}{|lXl|}\hline
. & start \the\Start{} - end \the\End & . \\
. & filled space \the\dp\ParBox & . \\
.&.&.\\
.&.&.\\
.&.&.\\
.&.&.\\
.&.&.\\
.&.&.\\
.&.&.\\
.&.&.\\
.&.&.\\
.&.&.\\
.&.&.\\
.&.&.\\
& \framebox{\usebox{\ParBox}} &\\
\hline
\end{tabularx}%

\vskip-\Start
\vskip-\End
\zsaveposy{start}%
\vfill\zsaveposy{end}%
\end{document}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.