I have frequent enumerated lists where the items in the list are of uneven heights, normally because of display-math items like dfrac
. (Yes, I'm aware of the typographic issues with display math presented inline, but this layout is a requirement for the document type I'm preparing.) To give the list even spacing, I'm currently using vphantom
, as shown in the MWE below:
\documentclass{article}
\usepackage{enumitem}
\usepackage{mathtools}
\begin{document}
\begin{enumerate}[label=\Alph*)]
\item $x = y^2 + 4y + 13 \vphantom{\sqrt{\dfrac{x-4}{2}}}$
\item $x = 2\left(y + 1\right)^2 + 4 \vphantom{\sqrt{\dfrac{x-4}{2}}}$
\item $y = 2\left(x + 1 \right)^2 - 4 \vphantom{\sqrt{\dfrac{x-4}{2}}}$
\item $y = -\sqrt{\dfrac{x-4}{2}}+2$
\end{enumerate}
\end{document}
What I would like to do is dispense with the end-user needing to remember to add vphantom
all the time. As best as I can tell, I need a command that will keep track of the height of each line in the list, save the largest one to the aux file, and insert a strut in each item that takes its size from that saved value. Is there a package that already does this? Or alternatively, how would I create such a command? (I still haven't mastered the the aux file.)
Edit:
Heiko's solution gave me the clue I needed to finish the job. Here's what I did to wrap the whole thing so that I don't have to fuss with definitions each time:
\documentclass{article}
\usepackage{enumitem}
\usepackage{mathtools}
\usepackage{etoolbox}
\usepackage{xparse}
\newcommand{\choicestext}{}
\newcommand{\phantomtext}{}
\newcommand{\choice}[1]{%
\xappto\choicestext{\unexpanded{\item #1\vph}}%
\xappto\phantomtext{\unexpanded{\{#1\}}}
}
\newenvironment{choices}{%
\renewcommand{\choicestext}{}%
\renewcommand{\phantomtext}{}%
}{%
\def\vph{\vphantom{\smash[b]\phantomtext}}%
\begin{enumerate}[label=\Alph*)]
\choicestext
\end{enumerate}
}
\begin{document}
\begin{choices}
\choice{$x = y^2 + 4y + 13$}
\choice{$x = 2\left(y + 1\right)^2 + 4$}
\choice{$y = 2\left(x + 1 \right)^2 - 4$}
\choice{$y = -\sqrt{\dfrac{x-4}{2}}+2$}
\end{choices}
\end{document}
\newcommand*{\MaxSize}{\vphantom{\sqrt{\dfrac{x-4}{2}}}}
and i modify\item
to insert\MaxSize
on each line so that you don't have to manually add this.\MaxSize
will be different for each question. In other words, no single, predefined value is going to work for the whole document.\MaxSize
. Thus partially-automated