# Minipage maximum height

I want to make template for texts of different length with minipage having maximum height of 62 mm. If text isn't very long, minipage must have its natural height. Is it a way to do it?

\documentclass{book}

\usepackage{lipsum}

\pagenumbering{gobble}

\begin{document}

Foo

\vfill

\begin{minipage}[t][62mm][t]{\textwidth}

\lipsum

\end{minipage}
}

\newpage

Foo

\vfill

\begin{minipage}[t][62mm][t]{\textwidth}

Bar

\end{minipage}
}

\end{document}


• @Sigur For what? I need minipages of different height with maximum of 62 mm. – web-stranger Apr 28 '15 at 13:18
• Oh, I see. Sorry. – Sigur Apr 28 '15 at 13:21
• What should happen, if the natural height of the box is larger than 62mm? Which depths of the box are allowed? – Heiko Oberdiek Apr 28 '15 at 14:42
• @Heiko Oberdiek, nothing. In that case text should be replaced. – web-stranger Apr 28 '15 at 14:47
• What's the purpose of a maximum height, if nothing should happen, when the box is larger? Which text should be replaced when by what? – Heiko Oberdiek Apr 28 '15 at 14:58

Maybe this is what you want:

\documentclass{book}

\usepackage{lipsum}
\usepackage{xparse}

\newsavebox{\strangeminipagebox}
\NewDocumentEnvironment{strangeminipage}{O{\textwidth}}
{%
\begin{lrbox}{\strangeminipagebox}
\begin{minipage}[t]{\dimexpr#1-2\fboxsep-2\fboxrule}%
}
{%
\end{minipage}\end{lrbox}%
\ifdim\dimexpr\ht\strangeminipagebox+\dp\strangeminipagebox<62mm\relax
\framebox[#1]{\usebox{\strangeminipagebox}}%
\else
\makebox[0pt][l]{%
\fbox{%
\vrule height \ht\strangeminipagebox
depth \dimexpr62mm-\ht\strangeminipagebox\relax
width 0pt
\hspace{\dimexpr#1-2\fboxsep-2\fboxrule}%
}%
}%
\makebox[#1]{\usebox{\strangeminipagebox}}%
\fi
}

\begin{document}

\noindent
\begin{strangeminipage}
\lipsum[1-3]
\end{strangeminipage}

\bigskip

\noindent
\begin{strangeminipage}[.5\textwidth]
Bar
\end{strangeminipage}

\end{document}


• thank you very much! could you explain me {O{\textwidth}} parameter? How can I change it for some another variable? – web-stranger Apr 28 '15 at 14:42
• @web-stranger O{\textwidth} means that the environment gets an optional argument, with default value \textwidth. I used it in the second example, to show that it reduces the width. – egreg Apr 28 '15 at 14:47