2

Much like this question, I want to force a table to fit within the vertical page margins.

Any ideas?

Edit:

Margin size: \usepackage[left=3cm,right=3cm,textheight=23.5cm]{geometry}

Present situation: Output and LyX text.

10
  • Put it in a box and scale it to the text height. It would help us help you if you gave us a minimum working example to start with. Jan 31, 2014 at 14:09
  • I have edited my question to elaborate on my problem. By "box", do you mean float? @StevenB.Segletes Jan 31, 2014 at 14:32
  • 2
    By box, I mean something like \newsavebox\mybox\sbox{\mybox}{your table goes here}\scalebox{scale factor}{\usebox{\mybox}}, where \scalebox is part of the graphicx package. scale factor is a number. The picture helps, but the code you used to get there would be more helpful, so that those who are willing to help you don't have to retype it all from scratch. Jan 31, 2014 at 14:37
  • 1
    If you would like, I will turn it into an answer, using typical tabular material. Jan 31, 2014 at 14:51
  • 1
    Well, it won't work with a float, but if it is just the tabular you need resized, then my scalerel package has a macro \scaleto{tabular material goes here}{\textheight} Jan 31, 2014 at 15:34

1 Answer 1

2

In my comment, I advocated something like:

\newsavebox\mybox
\sbox{\mybox}{your table goes here}
\scalebox{scale factor}{\usebox{\mybox}}

where scalefactor is a number and your table is something like a tabular. In this illustrative example below, I first set the text height shorter (2.8") just so it is easier to see what is going on. The first thing I do I set a large tabular without any changes. Because it exceeds the length of page 1, it ends up on page 2, and you see that it stretches down to the page number.

So, after clearing a page, I show how placing the table into a box and scaling it to a size smaller than unity can resolve the height issue (page 3). Of course, the font size is no longer uniform through the document.

On page 4, I show how this approach can be incorporated into a float, such as a table.

\documentclass[12pt]{article}
\usepackage{graphicx}
\textheight 2.8in
\begin{document}
{\centering
\begin{tabular}{|l|l|}
\hline
Variable & description of the variable\\
\hline
Variable & description\\
\hline
Variable & description\\
\hline
Variable & description\\
\hline
Variable & description\\
\hline
Variable & description\\
\hline
Variable & description\\
\hline
Variable & description\\
\hline
Variable & description\\
\hline
Variable & description\\
\hline
Variable & description\\
\hline
Variable & description\\
\hline
Variable & description\\
\hline
Variable & description\\
\hline
Variable & description\\
\hline
\end{tabular}\par
}
\clearpage
\newsavebox\mybox
\sbox{\mybox}{%
\begin{tabular}{|l|l|}
\hline
Variable & description of the variable\\
\hline
Variable & description\\
\hline
Variable & description\\
\hline
Variable & description\\
\hline
Variable & description\\
\hline
Variable & description\\
\hline
Variable & description\\
\hline
Variable & description\\
\hline
Variable & description\\
\hline
Variable & description\\
\hline
Variable & description\\
\hline
Variable & description\\
\hline
Variable & description\\
\hline
Variable & description\\
\hline
Variable & description\\
\hline
\end{tabular}
}
{\centering\scalebox{.9}{\usebox{\mybox}}\par}
\clearpage
\begin{table}
\caption{My caption}
{\centering\scalebox{.85}{\usebox{\mybox}}\par}
\end{table}
\end{document}

enter image description here

If the table to be scaled is not a float, but merely a tabular, it can be scaled exactly to the \textheight using the \scaleto{object}{height} feature of the scalerel package:

\documentclass[12pt]{article}
\textheight 6in
\usepackage{scalerel}
\begin{document}
\newsavebox\mybox
\sbox{\mybox}{%
\begin{tabular}{|l|l|}
\hline
Variable & description of the variable\\
\hline
Variable & description\\
\hline
Variable & description\\
\hline
Variable & description\\
\hline
Variable & description\\
\hline
Variable & description\\
\hline
Variable & description\\
\hline
Variable & description\\
\hline
Variable & description\\
\hline
Variable & description\\
\hline
Variable & description\\
\hline
Variable & description\\
\hline
Variable & description\\
\hline
Variable & description\\
\hline
Variable & description\\
\hline
\end{tabular}
}
{\centering\scaleto{\usebox{\mybox}}{\textheight}\par}

\end{document}

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.