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:
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It only takes a minute to sign up.
Sign up to join this communityMuch 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:
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}
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}
\newsavebox\mybox\sbox{\mybox}{your table goes here}\scalebox{scale factor}{\usebox{\mybox}}
, where\scalebox
is part of thegraphicx
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.tabular
you need resized, then myscalerel
package has a macro\scaleto{tabular material goes here}{\textheight}