# How do I write code in LaTeX for this system of linear equations?

Consider: I am having a hard time writing this system of linear equations in LaTeX. How can I do it?

• \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 Feb 22, 2018 at 1:07
• A minor tweak that you can make to any of the other answers is that, if you \usepackage{mathtools} instead of amsmath, 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. Feb 22, 2018 at 7:53

The 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} • Perfect (as usual) alignment, specially the vertical dots. Feb 22, 2018 at 1:25

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. • how you know, that op like to have such system of equation? Feb 22, 2018 at 1:14
• @Zarko, sorry?! Feb 22, 2018 at 1:15
• i wonder, because provided images in question doesn't imply this :-) (as i suggest in comment, without of curly brace on the left side equation system ...) Feb 22, 2018 at 1:18
• Well, as I said, I'd do like this, with braces. But if OP wishes, just delete the braces. It is better to give a little more instead of waiting OP ask for a brace. Feb 22, 2018 at 1:24

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}

• Oh, egreg had used amsmath. Feb 22, 2018 at 1:54

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 • amsmath provides pmatrix environment also, if you wish. Feb 22, 2018 at 16:01
• Consider the nicematrix package. Mar 8, 2018 at 16:56

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: 