4

I have two minipages side-by-side, and one is of a larger font size than the other – this is to produce a title. However, the baselines of the minipages are aligned, and not the top. I would prefer for the text in both minipages to align at their tops rather than their baselines.

Here is a minimal working example, and its output:

\documentclass{article}

% Show the frame to see the line I would like to align at.
\usepackage[showframe]{geometry} 

\begin{document}
\noindent
\begin{minipage}[t]{80pt}\huge Baseline\end{minipage}
\begin{minipage}[t]{100pt}Baseline baseline with lots and lots of text, consider this a paragraph\end{minipage}
\end{document}

Produced Output

To be clear, I would like for the paragraph on the right to touch the top line just like the \huge text on the left.

I tried to align the top by first having a \rule{0pt}{1em}\vspace{-1em} before the paragraphs start, but this doesn't work, presumably due to the change in line separation in different sizes, and the alignment gets even worse. I won't show the result but here's the code for that anyway:

\documentclass{article}
\usepackage[showframe]{geometry} 
% This does NOT produce the desired result.
\begin{document}
\noindent
\begin{minipage}[t]{80pt}%
    \rule{0pt}{1em}\vspace{-1em}

    \huge Baseline
\end{minipage}
\begin{minipage}[t]{100pt}%
    \rule{0pt}{1em}\vspace{-1em}

    Baseline baseline with lots and lots of text, consider this a paragraph
\end{minipage}
\end{document}

So: how can I align the tops of these minipages, rather than aligning their top baseline?

3
  • You can add a \vspace{0pt} in the beginning of each one. Commented Mar 21, 2019 at 14:32
  • @PhelypeOleinik This aligns them, but adds extra space at the top - how can I remove this extra space? Presumably it is another \baselineskip, right? EDIT: it's 1em and this solves the issue.
    – AJF
    Commented Mar 21, 2019 at 14:34
  • Hm... There's that... Sorry, I don't know. I'll retract my close vote. It looks like that if you set \topskip=0pt before the minipages (and make sure you restore it after) that extra space will disappear. I'm not sure if this is correct, though. Commented Mar 21, 2019 at 14:38

4 Answers 4

6

As pointed out by @Phelype Oleninik, adding a \vspace{0pt} aligns the two with an extra line which is \topskip tall. Hence adding the line \vspace{0pt}\vspace{-\topskip}, or even just \vspace{-\topskip}, aligns the two paragraphs at the top of their minipages. Here is working code:

\documentclass{article}
\usepackage[showframe]{geometry} 
\begin{document}
\noindent
\begin{minipage}[t]{80pt}%
    \vspace{-\topskip}
    \huge Baseline
\end{minipage}
\begin{minipage}[t]{100pt}%
    \vspace{-\topskip}
    Baseline baseline with lots and lots of text, consider this a paragraph
\end{minipage}
\end{document}

Result: enter image description here

2
  • Coincidentally (more or less) 1em is 10.00002pt, and the \topskip is 10pt by default... Perhaps \vspace{-\topskip} :) Commented Mar 21, 2019 at 14:44
  • @PhelypeOleinik A good point, \topskip it is! Using \topskip also produces better results with higher point-sizes.
    – AJF
    Commented Mar 21, 2019 at 14:49
3

The \belowbaseline[<depth>]{<content>} macro of stackengine. Note, there is a corresponding \abovebaseline[<height>]{<content>} macro.

\documentclass{article}
\usepackage{stackengine}
% Show the frame to see the line I would like to align at.
\usepackage[showframe]{geometry} 

\begin{document}
\noindent
\belowbaseline[-\ht\strutbox]{\begin{minipage}[t]{80pt}\huge Baseline\end{minipage}}
\belowbaseline[-\ht\strutbox]{\begin{minipage}[t]{100pt}Baseline baseline with lots and 
  lots of text, consider this a paragraph\end{minipage}}
\end{document}

enter image description here

2

This seems to also work:

enter image description here

\documentclass{article}

% Show the frame to see the line I would like to align at.
\usepackage[showframe]{geometry} 

\begin{document}
\noindent
\raisebox{\baselineskip}{\raisebox{-\height}{\begin{minipage}[t]{80pt}\huge Baseline\end{minipage}}
                         \raisebox{-\height}{\begin{minipage}[t]{100pt}Baseline baseline with lots and lots of text, consider this a paragraph\end{minipage}}}
\end{document}
2

One can use \raisebox to move the baseline of a box (with TeX everything is a box). It should be noted that the first baseline of a page is located \topskip below the actual top. Otherwise, one should use \ht\strutbox.

\documentclass{article}

% Show the frame to see the line I would like to align at.
\usepackage[showframe]{geometry} 

\begin{document}
\noindent
\raisebox{\dimexpr \topskip-\height}{\begin{minipage}[t]{80pt}\huge Baseline\end{minipage}}
\raisebox{\dimexpr \topskip-\height}{\begin{minipage}[t]{100pt}Baseline baseline with lots and lots of text, consider this a paragraph\end{minipage}}
\end{document}

demo

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .