# How to Align Equations to Top of Minipage

I have two align environments in 2 minipages and I want them to be aligned at the very top. I am usually able to do it with 2 regular equations, but it doesn't work when I tried doing it on the two align environment, I end up getting a gap on the left minipage so it looks a bit off. Below is my code and output.

\documentclass[a4paper, 11pt, letterpaper]{article}
\usepackage{comment}
\usepackage{fullpage}
\usepackage{amssymb}
\usepackage{mathtools,amsthm}
\usepackage{tabularx}
\begin{document}
\begin{minipage}[t]{0.6\textwidth}
\vspace{0pt}
\begin{align*}
\f{dy}{dx} &= 1\cdot (2x-1)^2 + (x+3)\cdot 2 \cdot (2x-1) \cdot 2\\
&= (2x-1)^2 + 4(x+3)(2x-1)\\
&= (2x-1)[(2x-1)+4(x+3)]\\
&= (2x-1)(2x-1+4x+12)\\
&= (2x-1)(6x+11)
\end{align*}
\end{minipage}
\hfill
\begin{minipage}[t]{0.3\textwidth}
\vspace{0pt}
\begin{tabular}{|p{\textwidth}}
{\!\begin{aligned} &u=x+3\\ &v=(2x-1)^2\\ &u'=1\\ &v'=4(2x-1) \end{aligned}}
\end{tabular}
\end{minipage}
\end{document}


Thanks for any help!

This probably achieves what you want (I made the code compilable by replacing \f by \frac and changed the minipage alignment to [h]):

\documentclass[a4paper, 11pt, letterpaper]{article}
\usepackage{comment}
\usepackage{fullpage}
\usepackage{amssymb}
\usepackage{mathtools,amsthm}
\usepackage{tabularx}
\begin{document}
\begin{minipage}[h]{0.6\textwidth}
\vspace{0pt}
\begin{align*}
\frac{dy}{dx} &= 1\cdot (2x-1)^2 + (x+3)\cdot 2 \cdot (2x-1) \cdot 2\\
&= (2x-1)^2 + 4(x+3)(2x-1)\\
&= (2x-1)[(2x-1)+4(x+3)]\\
&= (2x-1)(2x-1+4x+12)\\
&= (2x-1)(6x+11)
\end{align*}
\end{minipage}
\hfill
\begin{minipage}[h]{0.3\textwidth}
\vspace{0pt}
\begin{tabular}{|p{\textwidth}}
{\!\begin{aligned} &u=x+3\\ &v=(2x-1)^2\\ &u'=1\\ &v'=4(2x-1) \end{aligned}}
\end{tabular}
\end{minipage}
\end{document}


Just for the records: if I wanted to get the vertical line, I'd use

\documentclass[a4paper, 11pt]{article} % either letterpaper or a4paper
\usepackage{fullpage}
\usepackage{amssymb}
\usepackage{mathtools}
\usepackage{tikz}
\newcommand{\tikznode}[2]{%
\tikz[remember picture,baseline=(#1.base),inner sep=0pt] \node (#1) {$#2$};%
}%from https://tex.stackexchange.com/questions/402462/tikz-equivalent-of-pstricks-commands-ncbar-and-rnode/402466#402466
\begin{document}
\begin{align*}
\frac{\mathrm{d}y}{\mathrm{d}x} &= 1\cdot (2x-1)^2 + (x+3)\cdot 2 \cdot (2x-1) \cdot 2
& \tikznode{u}{\strut}u&=x+3\\
&= (2x-1)^2 + 4(x+3)(2x-1)
& v&=(2x-1)^2\\
&= (2x-1)[(2x-1)+4(x+3)]
&u'&=1\\
&= (2x-1)(2x-1+4x+12)
&  \tikznode{v}{\strut}~v'&=4(2x-1)\\
&= (2x-1)(6x+11)
\end{align*}
\tikz[overlay,remember picture]{\draw (v|-u.north)--(v.south);}
\end{document}


Note that I kicked out some of the unnecessary packages and also removed one of the conflicting options (letterpaper).

• Oh sorry, I forgot to change the \f to \frac. Thank you for your answer. However I don't understand the second part where you say "horizontal line". I don't see a horizontal line in the second image. Commented Feb 14, 2018 at 3:19
• @Nanoputian You're right. It should be vertical. In my burrow it is so dark that I'm often confusing the directions. ;-)
– user121799
Commented Feb 14, 2018 at 3:27

You don't need minipages: it all can be done with alignat*:

\documentclass[a4paper, 11pt, letterpaper]{article}

\usepackage{comment}
\usepackage{fullpage}
\usepackage{amssymb}
\usepackage{empheq, amsthm}

\begin{document}

\begin{alignat*}{2}
\smash[b]{\frac{dy}{dx}} &= 1\cdot (2x-1)^2 + (x+3)\cdot 2 \cdot (2x-1) \cdot 2%
& \hspace{4em} \smash{\rule[-12ex]{0.4pt}{14ex}}\enspace & u=x+3 \\
&= (2x-1)^2 + 4(x+3)(2x-1)& &v=(2x-1)^2 \\
&= (2x-1)[(2x-1)+4(x+3)] & &u'=1 \\
&= (2x-1)(2x-1+4x+12) & & v'=4(2x-1) \\
&= (2x-1)(6x+11)
\end{alignat*}

\end{document}


You seem to want aligned and array side-to-side:

\documentclass[a4paper,11pt]{article}
\usepackage{mathtools}
\usepackage{array}

\begin{document}

\begin{equation*}
\begin{aligned}[t]
\frac{dy}{dx}
&= 1\cdot (2x-1)^2 + (x+3)\cdot 2 \cdot (2x-1) \cdot 2\\
&= (2x-1)^2 + 4(x+3)(2x-1)\\
&= (2x-1)[(2x-1)+4(x+3)]\\
&= (2x-1)(2x-1+4x+12)\\
&= (2x-1)(6x+11)
\end{aligned}
\begin{array}[t]{|l@{}>{{}}l}
u&=x+3\\
v&=(2x-1)^2\\
u'&=1\\
v'&=4(2x-1)
\end{array}
\end{equation*}

\end{document}


I used left alignment for the first column in the array because the result seems more symmetric than with the usual right alignment.

Note that a4paper and letterpaper override each other; so just one should be specified.