# How to make a box with a height based on multiples of the current line height

How can I create (in XeLaTeX) a box that has a defined height in multiples of lines that keeps this size 100% without any additional spacings?

\documentclass{article}

\usepackage{lipsum}
\usepackage{multicol}

\newcommand{\mybox}[2]{\parbox[t][#1\baselineskip]{\columnwidth}{#2}}

\begin{document}
\begin{multicols}{2}\raggedcolumns

\lipsum[1]
\mybox{3}{Some more text}
\lipsum[2-8]

\end{multicols}
\end{document}


The mybox should create a 3-line box. However, after that box, the base lines seem to be off ~1pt if compared to the right column. I've tried a lot of different types of boxes, spacers, minipages and such, and have not yet a solution. Often the box has the correct height, but it does not properly fit into the surrounding, throwing baseline-alignment in the other column off.

In the solution I look for, the first priority should be exact height, no matter what happens inside or right next to the box. The box might contain text, but also images or maybe small tables - it's purpose is to create a reliable "reserved space". Or, to be more precise, the base lines in both columns before and after the box should always stay aligned. If odd fonts are used with artistic overlength letters (both upwards and downwards, like in handwriting), the box should not make space for that. If more content is in the box than there is space, it's ok to either crop or to overflow into the surrounding, or if it looks odd what happens inside the box, but the specified hight in lines must be enforced. Also, the solution should not require hardcoded values (like point sizes for line heights, skips or spacing) but work with any text/font size that is currently in use.

-

You have to disable the interline skip after the \parbox:

\documentclass{article}
\usepackage[latin]{babel} % just to avoid over or underfull boxes

\usepackage{lipsum}
\usepackage{multicol}

\newcommand{\mybox}[2]{%
\par\noindent
\parbox[t][#1\baselineskip][t]{\columnwidth}{#2}%
\par\nointerlineskip
\noindent\ignorespaces
}

\begin{document}
\begin{multicols}{2}\raggedcolumns

\lipsum[2]
\mybox{3}{\bfseries Some more text that wraps to the following line}
\lipsum[3-5]

\end{multicols}
\end{document}


-
to maintain paragraph-like look, one could save the \parindent in some dimension register, and reset its value as the first thing inside the parbox. Then one would take out the \noindent before \ignorespaces. –  jfbu Jan 26 '13 at 11:40
This solution seems to work a better than the one proposed by jfbu, but also if I put a tabular instead of just text in it, the height gets wrong. In this case, it seems if I make a 6-line mybox, and putting a (smaller) tabular in it, mybox occupies ~6.5 lines. –  TeXter Feb 24 '13 at 10:20
@TeXter Beware that the default vertical positioning of a tabular is similar to \parbox (with implied [c] optional argument). Without an example it's difficult to say more, but possibly \begin{tabular}[t] can save your day. –  egreg Feb 24 '13 at 22:36
I was hoping to find a solution for the question that is independent of what is going on inside the "mybox", so that I always can rely on the correct height, worst case overfflowing content outside or just cropping it. I'll investigate into the [t] however... –  TeXter Feb 26 '13 at 5:39

A different approach:

\documentclass{article}

\usepackage{lipsum}
\usepackage{multicol}

\newcommand{\myfixedsizepar}[1]{\par
\def\x{\par\vskip-\prevgraf\baselineskip\vskip#1\baselineskip}%
\bgroup\aftergroup\x\let\next=}

\begin{document}\thispagestyle{empty}

\begin{multicols}{2}\raggedcolumns

\lipsum[1]
\myfixedsizepar{3}{Some more text some more text on three lines}
\lipsum[2]
\myfixedsizepar{5}{Some more text some more text on five lines}
\lipsum[3]

\end{multicols}
\end{document}


And, here is a variant (possibly useful in another context) which adjusts the height only if it is less than the asked-for minimal number of times the baselineskip:

\newcommand{\myminimumsizepar}[1]{\par
\def\x{\par
\ifnum\prevgraf<#1 \vskip-\prevgraf\baselineskip\vskip#1\baselineskip\fi}%
\bgroup\aftergroup\x\let\next=}


-
This seems to work fine for text, but if i put a small tabular inside, it seems that it uses the "first" line for the tabular, stretching that first line, and adding the remaining lines right below it. –  TeXter Feb 24 '13 at 10:16