I have seen a similar question to this one:
However, I do not want to resize my table so it fits inside the width of a page (I already do that without converting it to an image), I want to shrink my table's height so it does not occupy two pages (or more).
I saw some possible solutions like longtable
but they split my table into 2 and I do not want that.
Am I forced to convert my table to an image by using the \resizebox
from the graphicsx
package, or do I have other options?
Best Answer
You are not forced to convert your long table in an image using
\resizebox
although this command is supplied by thegraphicx
package. The table will be still a table.You can define the width and/or the height of the resized table with this command. Note that fixing both measures the fonts may be are not reduced proportionally, so usually is better left one dimension as
{!}
.You can also reduce the vertical spacing
\arraystretch
to reduce the font as less as possible, and may be using another font as\tiny
to change sightly the font proportions.Vertical lines are always evil, but in this case also the horizontal lines for the same reason, specially when
\arraystretch
is reduced , except the header lines and the bottom line. The packagebooktabs
make a good job for this task. Experiment with this minimal working example:Note that some like:
\resizebox{!}{\textheight}{ ...}
will not produce a table as long as the text heigth, because you are defining here only the height of the box, but in the starred form, it refers to the height + depth, that is:
\resizebox*{!}{\textheight}{ ...}
will make the table as long as
\textheight
(556.4pt in the above MWE).Another command that you can use, from the same package
graphicx
, is\scalebox
. The problem here is that you must have some idea of how the scaling should be, or experiment with the scaling values until you obtain what you want. To test it, simple replace in the MWE the\resizebox
command by:Edit: The "Dimension too large" error of your comment is a problem of the table design, not of the
\resizebox
command. LaTeX cannot wrap the text insidel
eft,r
ight andc
entered columns. For columns with long text, you must use thep{width}
orm{width}
columns in atabular
environment. Another option is theL
,C
,R
columns oftabulary
environment or theX
column of thetabularx
environment. These environments need the package of the same name and the total width of the table as first argument. For example:I change your code to use
tabularx
with custom columns that use a different font, colors and justification. I added also row colors to avoid vertical and most horizontal lines, for the rest use those of thebooktabs
package and not\hline
. Thi is the result: