4

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}

enter image description here

Thanks for any help!

3

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}

enter image description here

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}

enter image description here

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. – Nanoputian Feb 14 '18 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. ;-) – marmot Feb 14 '18 at 3:27
5

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} 

enter image description here

5

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}
\qquad
\begin{array}[t]{|l@{}>{{}}l}
u&=x+3\\
v&=(2x-1)^2\\
u'&=1\\
v'&=4(2x-1)
\end{array}
\end{equation*}

\end{document}

enter image description here

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.