14

Is there a way to change lineskip such that the text fills up a certain space?

MWE

\documentclass{article}
\usepackage{blindtext}

\begin{document}
\begin{minipage}[c][\textheight]{\linewidth}
\blindtext
\end{minipage}
\end{document}

Where the first line is at the top of the page, and the last line is at the bottom, as if there were a \vfill after every line.

Ideally, any solution would be fairly robust and allow a wrapfigure like

Not so minimal working example

\documentclass{article}
\usepackage{blindtext}

\begin{document}
\noindent\begin{minipage}[c][\textheight]{\linewidth}
\blindtext
  \begin{wrapfigure}{r}{2in}
  \includegraphics[width=\linewidth]{picture.png}
  \end{wrapfigure}
  \blindtext
\end{minipage}
\end{document}

2 Answers2

13

You should use the [s] (stretch) option for the minipage:

\documentclass{article}
\usepackage[pass,showframe]{geometry}
\usepackage{blindtext}

\begin{document}
\noindent\begin{minipage}[c][\textheight][s]{\linewidth}
\baselineskip=1\baselineskip plus 1fill % stretch as much as needed
\lineskip=0pt plus 1fill % just for safety

\blindtext
\end{minipage}
\end{document}

The `geometry package is used just to show the frame.

enter image description here

egreg
  • 1,121,712
  • 1
    +1 Hmm I wonder who implemented that s option:( – David Carlisle Jan 09 '13 at 10:13
  • Where do we get details of all such mysterious options? –  Jan 09 '13 at 14:07
  • @HarishKumar The LaTeX manual or "The LaTeX Companion", for instance. – egreg Jan 09 '13 at 15:43
  • Thank you. I need some more GiB of memory inside my brain ;-) –  Jan 09 '13 at 15:46
  • This answer is really nice! I was really hoping to include a wrapfig in my minipage, but wrapfig overcalculates the space needed (as if it calculates the number of lines needed before the \baselineskip changes and then expands with the new \basselineskip). Is there any way to get around this? – Nathanael Farley Jan 09 '13 at 16:40
  • @NathanaelFarley Difficult to say without seeing what you're trying to do. – egreg Jan 09 '13 at 16:43
  • Updated my question to reflect more of what I'm trying to do. – Nathanael Farley Jan 09 '13 at 17:15
  • Fixed! If I add \baselineskip=20pt plus 1pt minus 1pt just before the wrapfigure and then reinstate \baselineskip=1\baselineskip plus 1fill at the beginning of the next paragraph, wrapfigure behaves correctly. – Nathanael Farley Jan 09 '13 at 18:09
6

Ooh good question (+1) learn something new every day.

Normally you could set \baselineskip to a stretch space and it would stretch to fill the space, but it is defeated by the boxing and unboxing that minipage does behind the scenes.

Possibly the simplest thing is to use a primitive \vbox and shrinkable glue.

\documentclass{article}
\usepackage{blindtext}

\begin{document}


\noindent\vbox to \textheight{\baselineskip=\textheight minus \textheight
\blindtext
}
\end{document}

enter image description here

David Carlisle
  • 757,742