Consider:
I am having a hard time writing this system of linear equations in LaTeX. How can I do it?
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It only takes a minute to sign up.
Sign up to join this communityThe difficult part is vertically aligning all variables. Here's a possible solution.
\documentclass{article}
\usepackage{amsmath}
\usepackage{array}
\begin{document}
\[
\setlength{\arraycolsep}{0pt}
\begin{array}{
l % X_i
>{{}}c<{{}} % =
l % a_ij
l % Z_j
>{{}}c<{{}} % +
l % a_ij
l % Z_j
>{{}}c<{{}} % + \dots +
l % a_ij
l % Z_j
>{{}}l % + m_i
}
X_1 &=& a_{11}&Z_1 &+& a_{12}&Z_2 &+\dots+& a_{1m}&Z_m &+ \mu_1 \\
&\vdots \\
X_i &=& a_{i1}&Z_1 &+& a_{i2}&Z_2 &+\dots+& a_{im}&Z_m &+ \mu_i \\
&\vdots \\
X_n &=& a_{n1}&Z_1 &+& a_{n2}&Z_2 &+\dots+& a_{nm}&Z_m &+ \mu_n
\end{array}
\]
\end{document}
I'd do like this:
\[\left\{
\begin{aligned}
X_1 &= a_{11}Z_1 + a_{12}Z_2 + \dots + a_{1m}Z_m + \mu_1\\
\vdots\\
X_i &= a_{i1}Z_1 + a_{i2}Z_2 + \dots + a_{im}Z_m + \mu_i \\
\vdots\\
X_n &= a_{n1}Z_1 + a_{n2}Z_2 + \dots + a_{nm}Z_m + \mu_n
\end{aligned}
\right.\]
Here's a solution that's very similar to @egreg's. The main difference is that all a_{ij}
coefficients are centered, not left-aligned, in their respective columns. This affects the appearance of the middle row.
\documentclass{article}
\usepackage{array} % for "\newcolumntype" macro
\newcolumntype{C}{>{{}}c<{{}}} % for columns that contain '=' and '+'
\begin{document}
\[
\setlength{\arraycolsep}{0pt}
\begin{array}{ c *{3}{Ccc} Cc }
X_1 &=& a_{11}&Z_1 &+& a_{12}&Z_2 &+\cdots+& a_{1m}&Z_m &+& \mu_1 \\
&\vdots \\
X_i &=& a_{i1}&Z_1 &+& a_{i2}&Z_2 &+\cdots+& a_{im}&Z_m &+& \mu_i \\
&\vdots \\
X_n &=& a_{n1}&Z_1 &+& a_{n2}&Z_2 &+\cdots+& a_{nm}&Z_m &+& \mu_n
\end{array}
\]
\end{document}
Do they need to be written in the form you specify, or can you instead have the system of equations in vector and matrix form? In vector and matrix form you could instead write the system of equations as, e.g.:
\begin{equation}
\left( \begin{array}{c} X_1 \\ \vdots \\ X_i \\ \vdots \\ X_n \end{array} \right) =
\left( \begin{array}{ccccc}
a_{11} & a_{12} & \cdots & a_{1m} & \mu_1 \\
\vdots & \vdots & \ddots & \vdots & \vdots \\
a_{i1} & a_{i2} & \cdots & a_{im} & \mu_i \\
\vdots & \vdots & \ddots & \vdots & \vdots \\
a_{n1} & a_{n2} & \cdots & a_{nm} & \mu_n
\end{array} \right)
\left( \begin{array}{c} Z_1 \\ Z_2 \\ \vdots \\ Z_m \\ 1 \end{array} \right)
\end{equation}
which gives
What would I use for the task is the alignedat
environment. The following code renders two versions, one with coefficients aligned to the left and the other one with coefficients aligned to the right. The former is easier, but as far as I understand, it's more customary to align system coefficients to the right (at least if they are numbers). The complicated part (probably overcomplicated, but I don't know a simple way of making one character to have width of another one) is to make \vdots
align with the =
signs:
\documentclass{article}
\usepackage{amsmath}
\newcommand\evdots{\mathrel{\setbox0=\hbox{$=$}\makebox[\wd0]{$\vdots$}}}
\begin{document}
\[
\begin{alignedat}{4}
X_1 &= a_{11}&Z_1 &+ a_{12}&Z_2 &+\dots+ a_{1m}&Z_m &+ \mu_1 \\
&\evdots \\
X_i &= a_{i1}&Z_1 &+ a_{i2}&Z_2 &+\dots+ a_{im}&Z_m &+ \mu_i \\
&\evdots{}\\
X_n &= a_{n1}&Z_1 &+ a_{n2}&Z_2 &+\dots+ a_{nm}&Z_m &+ \mu_n
\end{alignedat}
\]
\bigskip
\[
\begin{alignedat}{8}
X_1 &={}& a_{11}&Z_1 &&+{}& a_{12}&Z_2 &&+\dots+{}& a_{1m}&Z_m &&+{}& \mu_1 \\
&\evdots \\
X_i &={}& a_{i1}&Z_1 &&+{}& a_{i2}&Z_2 &&+\dots+{}& a_{im}&Z_m &&+{}& \mu_i \\
&\evdots{}\\
X_n &={}& a_{n1}&Z_1 &&+{}& a_{n2}&Z_2 &&+\dots+{}& a_{nm}&Z_m &&+{}& \mu_n
\end{alignedat}
\]
\end{document}
The output:
\begin{align*} X_1 & = a_{11}Z_1 + ...\\ \vdots & \\ X_i & a_{i1}Z_1 ... \end{align*}
. to make yourself familiar to equation settings, see en.wikibooks.org/wiki/LaTeX/Mathematics and then en.wikibooks.org/wiki/LaTeX/Advanced_Mathematics\usepackage{mathtools}
instead ofamsmath
, it includes commands\vdotswithin{=}
and\shortvdotswithin{=}
that produce vertical dots exactly centered within a column as wide as the=
sign. You’ll notice that egreg’s and miko’s are just a little off to the left.