5

What appears on my page is how I want it to look, but please advise on how I can do this with better code. I have \addtolength{\jot}{0.3ex} in the preamble.

\begin{flalign*}
      L&= \left(u^S\right)^{0.5}\left(u^T\right)^{0.5} - \lambda \left(u^S+u^T-9.9\right)\\[1ex]
\smash{\raisebox{-1.4\baselineskip}{$\left\{\rule{0cm}{1.5cm}\right.$}}
0=\dfrac{\textrm d L}{\textrm d u^S}&= 0.5\left(u^S\right)^{-0.5}\left(u^T\right)^{0.5}-\lambda \tag{1} \\
\implies\ \ \ 0=\dfrac{\textrm d L}{\textrm d u^T}&= \left(u^S\right)^{0.5}0.5\left(u^T\right)^{-0.5}-\lambda \tag{2} \\
u^S + u^T &= 9.9 \tag{3}
&\end{flalign*}

enter image description here

ahorn
  • 673

3 Answers3

8

Something has to give here unfortunately as amsmath doesn't support that kind of partial vertical+horizontal alignment out of the box, but only with some manual gymnastics. So on the whole I would do something similar to you, i.e. stick mainly with a basic alignment environent of amsmath, especially if you really try to align all four rows on the equation signs.

What I would do differently is a) move the large lbrace into a macro definition like this:

\newcommand\smashedlbrace[2][0]{\ 
   \smash{\raisebox{#1\baselineskip}%
                   {\mathsurround 0pt     % <- extra
                    $\left\{\rule{0cm}{#2cm}\right.$}}\ }

and make use of the fact that you have 3 equations to overlay, thus it is best placed after the \implies because then there is no need to raise or lower anything :-) but I made provisions for that via the optional argument.

b) Add some \phantom into the last equation to open it up matching the others

c) your extended \jot is matter of taste ... I like it as the whole thing otherwise looks quite cramped

d) probably a good idea to use a def like \dd as well to make things more readable; or even better use the esdiff package as @Bernard in his anser suggested

That gives us

\documentclass{article}
\usepackage{amsmath}

\newcommand\dd{\mathrm{d}}

\newcommand\smashedlbrace[2][0]{\ 
  \smash{\raisebox{#1\baselineskip}%
                  {\mathsurround 0pt     % <- extra for safety
                    $\left\{\rule{0cm}{#2cm}\right.$}}\ }

\begin{document}

\addtolength{\jot}{0.5ex}

\begin{flalign*}
     L&= \left(u^S\right)^{0.5}\left(u^T\right)^{0.5} - \lambda \left(u^S+u^T-9.9\right)\\
0=\dfrac{\textrm d L}{\dd u^S}&= 0.5\left(u^S\right)^{-0.5}\left(u^T\right)^{0.5}-\lambda \tag{1} \\
\implies
\smashedlbrace{1.3} 
   0=\dfrac{\dd L}{\dd u^T}&= \left(u^S\right)^{0.5}0.5\left(u^T\right)^{-0.5}-\lambda \tag{2} \\
u^S + u^T &= 9.9 \tag{3}
\phantom{\dfrac{L}{u^T}}         % to open up last equation
&\end{flalign*}

\end{document}

and compiled

enter image description here

  • I have an improvement, which lets your command be used for an even number of lines: {\mathsurround 0pt $\implies \left\{\rule{0cm}{#2cm}\right.$}}\ } – ahorn Apr 06 '17 at 10:36
  • @ahorn yes that is probably better, but then you may want to go all the way and add the "\implies" as a parameter value so that you can add something in front of it with ease. – Frank Mittelbach Apr 06 '17 at 10:46
5

Here is a solution based a empheq and esdiff, a package which greatly simplifies typing (partial) derivatives. Needless to load amsmath since empheq loadsmathtools , which loads amsmath:

\documentclass{article}
\usepackage{empheq, esdiff}
\usepackage[showframe]{geometry}

\begin{document}
\vspace*{3ex}
$ L= \left(u^S\right)^{0.5}\left(u^T\right)^{0.5} - \lambda\left(u^S+u^T-9.9\right)$\vspace{1ex}
\begin{empheq}[left=\implies\empheqlbrace]{flalign}
  &0=\diff{L}{u^S}= 0.5\left(u^S\right)^{-0.5}\left(u^T\right)^{0.5}-\lambda , & \\
  &0=\diff{ L}{u^T}= \left(u^S\right)^{0.5}0.5\left(u^T\right)^{-0.5}-\lambda,\\
  & u^S + u^T = 9.9.
\end{empheq}

\end{document} 

enter image description here

Bernard
  • 271,350
  • I like that but how can you get the alignment on the = sign for all four lines as well? – Frank Mittelbach Apr 02 '17 at 23:23
  • @ahorn: Sorry for the λ. My editor is configured so that it displays the Greek letter (I have a shortcut for that), but saves it as the usual \lambda, so it can compile. I've fixed the code. – Bernard Apr 04 '17 at 18:12
3

If you want to align all four lines but want the brace only to cover the last three lines, you can use an overlay with a tikz drawing. The command

\tikzcoord[optional vertical shift]{label}

defined as

\usepackage{tikz}
\newcommand\tikzcoord[2][0ex]%
  {\raisebox{#1}{\tikz[remember picture]\coordinate(#2);}}

labels a point in the equations for later reference in the tikz picture. The brace can be drawn using

\usetikzlibrary{decorations.pathreplacing}
...
\begin{tikzpicture}[remember picture,overlay]
\draw[decorate,decoration={brace,mirror}] ...
\end{tikzpicture}

enter image description here

\documentclass{article}
\usepackage{amsmath}
\newcommand\dd{\mathrm{d}}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing}
\newcommand\tikzcoord[2][0ex]{\raisebox{#1}{\tikz[remember picture]\coordinate(#2);}}
\begin{document}
\begin{flalign*}
  L & = \left(u^S\right)^{0.5}\left(u^T\right)^{0.5} - \lambda \left(u^S+u^T-9.9\right)\\[1ex]
  \tikzcoord[2.2ex]{a}\;\;
  0=\dfrac{\dd L}{\dd u^S}
    & = 0.5\left(u^S\right)^{-0.5}\left(u^T\right)^{0.5}-\lambda \tag{1} \\
  0=\dfrac{\dd L}{\dd u^T}
    & = \left(u^S\right)^{0.5}0.5\left(u^T\right)^{-0.5}-\lambda \tag{2} \\
  \tikzcoord[-0.5ex]{b}
  u^S + u^T 
    & = 9.9 \tag{3}
\end{flalign*}
\begin{tikzpicture}[remember picture,overlay]
\draw[decorate,decoration={brace,mirror},thick] (a) --node[left]{$\Rightarrow\;$} (a|-b);
\end{tikzpicture}
\end{document}
gernot
  • 49,614