The minipage
environment has options for making the top, bottom, or center of the minipage box line up with the baseline of the surrounding text. Is there a way to make it line up to the baseline of the first or last line of text inside the minipage?
I imagine I'd use \raisebox
, but how do I calculate the distance from the top of the minipage to the first line's baseline (or the bottom of the minipage to the last line's baseline)?
Update:
As indicated in the excellent answer below, minipage
already does what I want. The problem I had was that the \color
command was messing with the minipage in all sorts of bizarre ways. Putting a \strut
at the beginning and end of the minipage didn't fix it, but everything started working once I changed \color
to \textcolor
:
\documentclass{article}
\usepackage{color}
\usepackage{varwidth}
\newcommand{\sampletext}{testing (1)\\testing (2)}
\newcommand{\tmp}[2]{\fbox{\begin{varwidth}[#1]{0.8in}#2\end{varwidth}}}
\newcommand{\broken}[1]{\tmp{#1}{\color[rgb]{0,0,0.5}\sampletext}}%
\newcommand{\fixed}[1]{\tmp{#1}{\textcolor[rgb]{0,0,0.5}{\sampletext}}}%
\setlength{\parindent}{0pt}\setlength{\parskip}{\baselineskip}%
\begin{document}
with \verb|\color|:\\
before \broken{t} between \broken{c} between \broken{b} after
with \verb|\textcolor|:\\
before \fixed{t} between \fixed{c} between \fixed{b} after
\end{document}