Math & ScienceAlign Equations

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
sw3quant
Posts: 76
Joined: Tue Nov 02, 2010 11:40 pm

Align Equations

Post by sw3quant »

I have some latex code:

Code: Select all

\documentclass[10pt]{article}
\usepackage{amsmath,amssymb}
\usepackage{amsfonts}
\begin{document}
\begin{align*}%3.7
\begin{bmatrix}
y_1\\
\vdots\\
y_T
\end{bmatrix}
&=
\begin{bmatrix}
{\cal{G}}(x_{(:,1)},{\bf W})\\
\vdots\\
{\cal{G}}(x_{(:,T)},{\bf W})
\end{bmatrix}
&+
&\begin{bmatrix}
\epsilon_1\\
\vdots\\
\epsilon_T
\end{bmatrix}
=&
{\bf W}^T
\begin{bmatrix}
{\phi}_1(x_{(:,1)})^T\\
\vdots\\
{\phi}_T(x_{(:,T)})^T
\end{bmatrix}
+
\begin{bmatrix}
\epsilon_1\\
\vdots\\
\epsilon_T
\end{bmatrix} \\
{\bf Y} &= {\cal{G}}({\bf X},{\bf W}) &+ {\boldsymbol \epsilon}& =& {\bf W}^T{\bf \Phi({\bf X})} + {\boldsymbol \epsilon}
\end{align*}
\end{document} 
which gives,
latex.jpg
latex.jpg (38.45 KiB) Viewed 4936 times
in my code I wish to align the symbols. For example, I have a coloumn vector of y's. I wish to align this centrally with bold Y. I then also wish to align centrally with the equals sign. And also align centrally with the next set of expressions and so on.

I thought I could do this by using & symbol, but I dont seem able to. Can anyone help? thank you

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
User avatar
tom
Posts: 73
Joined: Thu Apr 18, 2013 4:02 am

Align Equations

Post by tom »

Hey!

You have to be a bit more careful with the alignments (&). Make sure they match in both lines. Now for central alignment of cells, that's a different story. I don't think there is a simple way using align*. You might be able to do it using {array} instead.

Code: Select all

\documentclass[10pt]{article}
\usepackage{amsmath,amssymb}
\usepackage{amsfonts}

\begin{document}
\begin{align*}%3.7
\begin{bmatrix}y_1\\\vdots\\y_T\end{bmatrix}
&=
\begin{bmatrix}{\cal{G}}(x_{(:,1)},{\bf W})\\\vdots\\{\cal{G}}(x_{(:,T)},{\bf W})\end{bmatrix}
&+&
\begin{bmatrix}\epsilon_1\\\vdots\\\epsilon_T\end{bmatrix}
&=&
{\bf W}^T
\begin{bmatrix}{\phi}_1(x_{(:,1)})^T\\\vdots\\{\phi}_T(x_{(:,T)})^T\end{bmatrix}
&+&
\begin{bmatrix}\epsilon_1\\\vdots\\\epsilon_T\end{bmatrix} \\
{\bf Y} &= {\cal{G}}({\bf X},{\bf W})&+& {\boldsymbol \epsilon}&= &{\bf W}^T{\bf \Phi({\bf X})} &+& {\boldsymbol \epsilon}
\end{align*}
\end{document}
Post Reply