0

How can I create environment that makes its content at least x units high? It should add white space under its content.

jiwopene
  • 179
  • Is there anything special that should occur when the content appears at the end of the page? For example, should everything be taken to the next page, or should the white space be gobbled? – Werner May 13 '21 at 16:13
  • The whole environment contents should be considered as one box. If there is not enough space on the page, it should go to the next. The environment will have width = \textwidth. – jiwopene May 13 '21 at 16:18
  • You say "considered as one box". Boxes do not break to the next page, so what you are talking about is not a box. – Steven B. Segletes May 13 '21 at 16:21
  • 2
    The whole box should go to the next page. – jiwopene May 13 '21 at 16:24

2 Answers2

4

Here a possible realization (if I have understood the request): the environment is basically a minipage, but before the latter starts there is an invisible rule with a given depth. The minimum depth can be passed as optional parameter to the environment. Here I have set the width of the rule to 1pt in order to show what is happening (which of course results in overfull \hboxes) but it should be of course 0pt.

% twocolumn for smaller snapshot
\documentclass[twocolumn]{article}

\newenvironment{foo}[1][8ex]{% \par\noindent \vrule depth#1 width1pt% <-- WRITE width0pt HERE \minipage[t]{\linewidth}% }{% \par\xdef\next{\the\prevdepth}\endminipage \par \prevdepth\next \ignorespacesafterend }

\begin{document}

See this and that, \begin{foo} Some text here. \end{foo} Some other text here. \begin{foo} Some longer text here which will take more than one line and in total more than the 5ex fixed by the invisible (well, not quite) rule on the left of this strange environment. \end{foo} Some other text here. \end{document}

enter image description here

campa
  • 31,130
  • Looks good but I want to have the environment contents on one page. (When there is not enough space, it should place everything to the next one.) – jiwopene May 13 '21 at 16:31
  • 1
    @campa, Could you explain the code put into the enddef of the new environment? – mcarchmiller May 13 '21 at 16:59
  • 1
    @mcarchmiller Not really, at least not in comments :-) Jokes aside, try commenting it out and you'll see why it's needed: the trouble with the t-aligned minipage (which is inherited by the TeX primitive \vtop) is that the baseline distance will be correct with the preceding line, but the line following the minipage will be too close. The \prevdepth stuff is a very low-level TeX trick to correct this. I picked that up years ago so I don't have a quick reference, but I'm sure the issue popped out on the site: I can't look for it now, I'll ping you later (or more likely tomorrow). – campa May 13 '21 at 17:05
  • 1
    @mcarchmiller Oh, wait, here is one: https://tex.stackexchange.com/q/34971/82917. – campa May 13 '21 at 17:07
  • Awesome, thanks! – mcarchmiller May 13 '21 at 17:17
1

I think what you are looking for is a minipage, which has the option to set the height. The problem is that a minipage will set the the indention and paragraph skipping to zero, but you may want to continue with the same format as your document. The solution is to save those settings and set them in the minipage. I have also made the environment height an optional parameter.

\documentclass[12pt]{article}

% For saving the current parskip and parindent \newlength{\saveparskip} \newlength{\saveparindent}

% Environment with option to set height \newenvironment{foo}[1][] {% \par\noindent% \setlength{\saveparskip}{\parskip}% \setlength{\saveparindent}{\parindent}% \begin{minipage}[t][#1]{\linewidth}% \setlength{\parskip}{\saveparskip}\setlength{\parindent}{\saveparindent} } {\strut\end{minipage}\par}

\setlength{\parskip}{2.5ex plus 0.5ex minus 0.2ex} \setlength{\parindent}{0.0in}

\begin{document}

Outside text \begin{foo} This is in the new environment \end{foo} outside text \begin{foo}[1in] This is in the new environment with set height \end{foo} outside text

\end{document}

enter image description here

  • 1
    Good point with the paragraph skip and indent within the minipage. However, if the content of the minipage is larger than the height set with the optional parameter, the following text will be overwritten. – campa May 13 '21 at 16:45