Math & ScienceAlignat not quite working

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
jaybz
Posts: 90
Joined: Sun Jul 11, 2010 6:02 pm

Alignat not quite working

Post by jaybz »

How can I include the line which is out side the "alignat" to be included and aligned with the equal sign?

Code: Select all

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{center}
 \begin{alignat*}{5}
f(x) &= e^{\,xtan(x)}  \nonumber \nonumber \nonumber \nonumber   \nonumber \\
\frac{d}{dx} &= e^{\,xtan(x)} \;&&\cdot  \frac{d}{dx} && \biggl(xtan(x) \biggr)   &&~ \\
~&= e^{\,xtan(x)} \;&&\cdot  &&\biggl(x\frac{d}{dx}tan(x) &&+ tan(x)\frac{d}{dx}(x) &&\biggr)    \\
~&= e^{\,xtan(x)} \;&&\cdot  &&\biggl( xsec^{2}(x) &&+ tan(x)(1) &&\biggr)    \\
~&= e^{\,xtan(x)} \;&&\cdot  &&\biggl( \quad xsec^{2}(x) &&+ tan(x) &&\biggr)   \\
\end{alignat*}

$= e^{\,xtan(x)}  \, xsec^{2}(x) \,+\, e^{\,xtan(x)}tan(x)  $

\end{center}
\end{document}
Attachments
»alignat« with outstanding line.
»alignat« with outstanding line.
alignat-problem.png (18.63 KiB) Viewed 4165 times
Last edited by jaybz on Sun Apr 24, 2011 7:00 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Alignat not quite working

Post by localghost »

Alignment of multi-line math expressions can be a real pain. If I understand you right, the code below should nearly do what you want.

Code: Select all

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{mathtools}  % loads »amsmath«

\begin{document}
  \begin{alignat*}{6}
    f(x)         &= e^{\,x\tan(x)} \\
    \frac{d}{dx} &= e^{\,x\tan(x)} & \,\cdot\, & \frac{d}{dx} &\biggl( && x\tan(x)             &                           &&\biggr) \\
                 &= e^{\,x\tan(x)} & \,\cdot\, &              &\biggl( && x\frac{d}{dx}\tan(x) &+   \tan(x)\frac{d}{dx}(x) &&\biggr) \\
                 &= e^{\,x\tan(x)} & \,\cdot\, &              &\biggl( && x\sec^{2}(x)         &+   \tan(x)(1)             &&\biggr) \\
                 &= e^{\,x\tan(x)} & \,\cdot\, &              &\biggl( && x\sec^{2}(x)         &+   \tan(x)                &&\biggr) \\[6\jot]
                 &= e^{\,x\tan(x)} & \,\cdot\, &              &        &&  x\sec^{2}(x)        &\:+                        &&        &e^{\,x\tan(x)}\tan(x)
  \end{alignat*}
\end{document}
The additional vertical space can simply be added as option to the line break command in the second last row.


Thorsten
Attachments
A suggestion for alignment.
A suggestion for alignment.
alignat-sample.png (19.89 KiB) Viewed 4163 times
User avatar
Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

Alignat not quite working

Post by Stefan Kottwitz »

Hi,

a quick fix in such cases could be using mathtools and one of its box macros:

Code: Select all

\usepackage{mathtools}
...
&= \mathrlap{e^{\,xtan(x)}  \, xsec^{2}(x) \,+\, e^{\,xtan(x)}tan(x)}
Note, that Thorsten used \tan and \sec to write the operator names un upright shape, that's very common.

Here's a complete example:

Code: Select all

\documentclass{article}
\usepackage{mathtools}
\begin{document}
\begin{alignat*}{5}
f(x) &= e^{\,x\tan(x)} \\
\frac{d}{dx} &= e^{\,x\tan(x)} \;&&\cdot  \frac{d}{dx} && \biggl(x\tan(x) \biggr)   &&~ \\
&= e^{\,x\tan(x)} \;&&\cdot  &&\biggl(x\frac{d}{dx}\tan(x) &&+ \tan(x)\frac{d}{dx}(x) &&\biggr)    \\
&= e^{\,x\tan(x)} \;&&\cdot  &&\biggl( x\sec^{2}(x) &&+ \tan(x)(1) &&\biggr)    \\
&= e^{\,x\tan(x)} \;&&\cdot  &&\biggl( \quad x\sec^{2}(x) &&+ \tan(x) &&\biggr)   \\
&= \mathrlap{e^{\,x\tan(x)}  \, x\sec^{2}(x) \,+\, e^{\,x\tan(x)}\tan(x) }
\end{alignat*}
\end{document}
alignat example
alignat example
alignat.png (7.8 KiB) Viewed 4162 times
Stefan
LaTeX.org admin
jaybz
Posts: 90
Joined: Sun Jul 11, 2010 6:02 pm

Alignat not quite working

Post by jaybz »

Yes Stefan_K, that looks good. Is the there a way to add a little vertical space between lines? Just using "\\\\" seems too much.

Just to others that don't have Mathtools you can install it like this.
"I'm on Ubuntu Maverick with Tex-live, I'm using Gummi and Texmaker as my Latex compiliers.

1) Download Mathtools from Ctan as part of the mh bundle
http://mirror.ctan.org/macros/latex/contrib/mh.zip
I downloaded it to the default directory called "Downloads" then:
1) Unzip the folder to Downloads.
2) From the terminal run this on ALL the .dtx files:
tex xxx.dtx , Where xxx is the file name. This will generate the .sty files.
3) sudo mkdir /usr/share/texmf-texlive/tex/latex/mathtools
4) cd /home/YOURPATHNAME/Downloads
5) sudo cp xxx.sty /usr/share/texmf-texlive/tex/latex/mathtools
where xxx is the name of all your .sty files.
6) YOURPATHNAME@ubuntu~$ sudo mktexlsr

You can run kpsewhich to verify that Latex is seeing the file.

Code: Select all

YOURPATHNAME@ubuntu:~$ kpsewhich mathtools.sty
/usr/share/texmf-texlive/tex/latex/mathtools/mathtools.sty
User avatar
Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

Alignat not quite working

Post by Stefan Kottwitz »

jaybz wrote:Is the there a way to add a little vertical space between lines? Just using "\\\\" seems too much.
Yes, there is. \\ takes an optional argument for such a vertical space. For example, just write \\[5pt]. If you need more space between the fomula lines in general, you could modify the length \jot.

Stefan
LaTeX.org admin
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Alignat not quite working

Post by localghost »

jaybz wrote:[…] Is the there a way to add a little vertical space between lines? Just using "\\\\" seems too much. […]
For a global solution you can modify the length \jot (default value 3pt) which determines this vertical space.

Code: Select all

\setlength{\jot}{6pt}
jaybz
Posts: 90
Joined: Sun Jul 11, 2010 6:02 pm

Re: Alignat not quite working

Post by jaybz »

Great, thank you both.
Post Reply