You can use the fitting
library of the tcolorbox
package. It provides a macro called \tcboxfit
which fits the font size of the content to the dimensions of the box. Alternatively, the option fit
for tcolorbox
does the same trick.
Note that the used font has to be resizable to all dimensions (vector font) to achieve the correct resizing.
The first example shows a framed box (can be adapted in many ways), the second one a box without a frame (the red border is just for displaying the size), the third example displays a box with title and fixed height.
\documentclass[a4paper]{article}
\usepackage[many]{tcolorbox}
\usepackage{lmodern}% or any other vector / postscript font
\usepackage{lipsum}
\begin{document}
\tcboxfit[width=6cm,height=6cm,nobeforeafter,
before=\noindent]{\lipsum[1]}
%
%
\begin{tcolorbox}[fit,width=6cm,height=6cm,blank,
borderline={0.4pt}{0pt}{red!20!white},
watermark text={6cm $\times$ 6cm},nobeforeafter]
\lipsum[1]
\end{tcolorbox}
\bigskip
\tcboxfit[height=6cm,title={This box has a height of 6cm},
colback=blue!5!white,colframe=blue!30!black,
before=\noindent]{\lipsum[1]}
\end{document}
\parbox
when the text overflows? You should get anoverfull hbox
message in that case.\parbox[t][2cm][t]{2cm}{\lipsum[1]}
- and there is no warning here.