# How to get uniform vertical space space after section title

I have encountered a problem when working with minipages. Consider the following example.

\documentclass{article}
\usepackage{mdframed}

\begin{document}

\begin{minipage}[t]{0.45\textwidth}
\section*{x}
\begin{mdframed}
Some text
\end{mdframed}
\end{minipage}
\hfill
\begin{minipage}[t]{0.45\textwidth}
\section*{y}
\begin{mdframed}
Some other text
\end{mdframed}
\end{minipage}

\end{document}


The box on the right will start further down the page because the section title has a different height (depth?). I want to align the tops of the two boxes. Is there a simple way to do this using the tools I have chosen, or should I try a different approach?

Edit: Added screenshot of problem.

You could add a strut:

\documentclass{article}
\usepackage{mdframed}

\begin{document}

\begin{minipage}[t]{0.45\textwidth}
\section*{\strut x}
\begin{mdframed}
Some text
\end{mdframed}
\end{minipage}
\hfill
\begin{minipage}[t]{0.45\textwidth}
\section*{\strut y}
\begin{mdframed}
Some other text
\end{mdframed}
\end{minipage}

\end{document}

• That works! I had tried using \vphantom{y}, but that does not seem to work in a section title (Edit: It works in the MWE, not in my original code. No idea why). I had not heard of \strut. – lydhvin Mar 10 '19 at 22:31

Also, you can add a \protect\vphantom{y} to have the same height. Note that anything inside sectioning commands must be robust or protected using \protect.

\documentclass{article}
\usepackage{mdframed}

\begin{document}

\begin{minipage}[t]{0.45\textwidth}
\section*{x\protect\vphantom{y}}
\begin{mdframed}
Some text
\end{mdframed}
\end{minipage}
\hfill
\begin{minipage}[t]{0.45\textwidth}
\section*{y}
\begin{mdframed}
Some other text
\end{mdframed}
\end{minipage}

\end{document}


• I had tried this, but for some reason it will not compile in my original document, and I don't have time to figure out why. It works in the MWE though. – lydhvin Mar 10 '19 at 22:33
• You need \protect for section to work, see my updated answer. – AboAmmar Mar 10 '19 at 22:34
• Yes, that works. Any advantage to using that over \strut? – lydhvin Mar 10 '19 at 22:37
• \strut is deeper than y, whereas \vphantom{y} is exactly as deep as y. – AboAmmar Mar 10 '19 at 23:35