[Tex/LaTex] Why does adjust box not resize to the dimensions given

adjustboxboxesparagraphs

Hi looking to understand this a little better. Why does adjustbox not resize the text in the following example so that it fits the dimensions I think I'm specifying. e.g a 4in x 4in box. Am I doing something wrong and how do I fix it?

\documentclass{article}
\usepackage{lipsum} 
\usepackage{adjustbox}
\begin{document}
\begin{adjustbox}{frame,max height=4in,max width=4in}
\parbox{4in}{
\lipsum[1-3]}    
\end{adjustbox}
\end{document}

Best Answer

Boxes in TeX have both height and depth. We can enquire about the dimensions of the box in question as follows.

\documentclass[10pt]{article}
\usepackage{adjustbox}
\usepackage{lipsum}
\begin{document}
\newsavebox\Abox
\savebox\Abox{\parbox{4in}{\lipsum[1-3]}}
\newlength\mydp
\newlength\myhg
\settodepth\mydp{\usebox{\Abox}}
\settoheight\myhg{\usebox{\Abox}}
\showthe\mydp
\showthe\myhg
\end{document}

In this way, we obtain a height of 204.97221pt and a depth of 209.97223pt. Since 1in=72.27pt, this means that the height and depth of the box are approximately 2.84in and 2.91in, respectively. Consequently, setting max height=4in has no effect. According to page 5 of the adjustbox package manual, totalheight is height plus depth, so if you want the actual height of the box on the page to be restricted to 4in you should use totalheight in place of height. To make the width of the box remain the same (so the aspect ratio of the box changes), you need to set width and totalheight.

\documentclass[10pt]{article}
\usepackage{adjustbox}
\usepackage{lipsum}
\begin{document}
\adjustbox{width=4in,totalheight=4in}{\parbox{4in}{\lipsum[1-3]}}
\end{document}
Related Question