# Adjusting space between array rows and columns

\documentclass[english]{article}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{babel}
\begin{document}
% ...
$\begin{array}{ccccc} x(1) & = & \frac{x(0)}{1} & = & x(0)\\ x(2) & = & \frac{x(1)}{2} & = & \frac{x(0)}{2}\\ x(3) & = & \frac{x(2)}{3} & = & \frac{x(0)}{2.3}\\ x(4) & = & \frac{x(3)}{4} & = & \frac{x(0)}{4!}\\ & & & & \vdots\\ x(n) & = & \frac{x(n-1)}{n} & = & \frac{x(0)}{n!} \end{array}$
% ...
\end{document}


Because of the fractions in the array cells, array elements are vertically too close to each other, they are literally touching to each other. Also the horizontal spacing is too much as you see in the image (screen shot from the output PDF file).

How do I make these cell-spacings look better?

• You can also add increase/decrease space between rows by supplying a positive/negative argument to \\ , i.e. \$2pt] and \\[-2pt] resp. add/remove 2pt of vertical space. Nov 14, 2018 at 16:06 • Shouldn't it be x(n-1)/n in the middle column, not x(n-1)/n! Nov 30, 2018 at 1:49 • Jun 14 at 12:03 ## 4 Answers \documentclass{article} \usepackage{amsmath} \begin{document} % ... \[\arraycolsep=1.4pt\def\arraystretch{2.2} \begin{array}{ccccc} x(1) & = & \dfrac{x(0)}{1} & = & x(0)\\ x(2) & = & \dfrac{x(1)}{2} & = & \dfrac{x(0)}{2}\\ x(3) & = & \dfrac{x(2)}{3} & = & \dfrac{x(0)}{2.3}\\ x(4) & = & \dfrac{x(3)}{4} & = & \dfrac{x(0)}{4!}\\ & & & & \vdots\\ x(n) & = & \dfrac{x(n-1)}{n!} & = & \dfrac{x(0)}{n!} \end{array}$
% ...
\end{document}


or for a left aligned:

\documentclass{article}
\usepackage{amsmath}
\begin{document}
% ...
$\arraycolsep=1.4pt\def\arraystretch{2.2} \begin{array}{rll} x(1) &= \dfrac{x(0)}{1} &= x(0)\\ x(2) &= \dfrac{x(1)}{2} &= \dfrac{x(0)}{2}\\ x(3) &= \dfrac{x(2)}{3} &= \dfrac{x(0)}{2.3}\\ x(4) &= \dfrac{x(3)}{4} &= \dfrac{x(0)}{4!}\\ & & \vdots\\ x(n) &= \dfrac{x(n-1)}{n!} &= \dfrac{x(0)}{n!} \end{array}$
% ...
\end{document}


• I tried applying your solution. It gives "Undefined control sequence." error on the dfrac commands. When I convert dfracs back to fracs the cells are separated as in your answer. I couldn't add the \usepackage{amsmath} command in my code, because LyX doesn't let me edit the source code. Could this error with dfrac be because of that? How should I do? Mar 21, 2013 at 20:02
• In Menu > Document > Settings... > LaTeX Preamble I added \usepackage{amsmath} in that large text box. Now when I try to preview my code in PDF it says LaTeX Error: 'amsmath.sty' not found.. I'm stuck, I don't know what to do. Mar 21, 2013 at 20:08
• @hkBattousai Herbert's solution might not work except when putting the whole "array" environment into an ERT/TeX code. Probably you want it to work with the "array" environment provided by LyX. It seems not possible to use { and } in a math environment without making a global def. Hence, you can move the part \arraycol....etch{2.2} outside of the math environment. As ERT put {\arraycolsep=1.4pt\def\arraystretch{2.2} (note the opening {) before the math environment and put } as ERT after the math environment. The opening { and the closing } will keep the change local. Working? Mar 21, 2013 at 20:10
• @e-birk: You can have everything inside the ERT mode! And \arraycolsep=1.4pt\def\arraystretch{2.2} will be enough. But without the LyX code I cannot say why it dosn't work for him
– user2478
Mar 21, 2013 at 20:19
• @e-birk: Copy and paste with everything bewtween $...$ works without a problem. LyX 2.0.3
– user2478
Mar 21, 2013 at 20:58

Use the alignat environment from the amsmath package. You can also adjust the space between lines with the \setstretch command from the setspace package.

\documentclass{article}
\usepackage{amsmath}
\usepackage{setspace}
\begin{document}
{\setstretch{2.25}
\begin{alignat*}{2}
x(1)   &=\frac{x(0)}{1}    &&= x(0)\\
x(2)   &=\frac{x(1)}{2}    &&= \frac{x(0)}{2}\\
x(3)   &=\frac{x(2)}{3}    &&= \frac{x(0)}{2.3}\\
x(4)   &=\frac{x(3)}{4}    &&= \frac{x(0)}{4!}\\
\vdots &                   && \\
x(n)   &=\frac{x(n-1)}{n!} &&= \frac{x(0)}{n!}
\end{alignat*}}
\end{document}


For the sake of completeness, you can also adjust the vertical space between two lines of the alignat* environment (this is also true for the align* environment) by specifying the spacing to use inside square brackets (for example [.5cm]) right after the newline symbol \\. Note that this value can also be a negative measurement if you want to reduce the vertical space between two lines. This is especially useful to individually correct the spacing between lines, such as when the line heights differ from one line to another (for example, all lines contain a fraction except one).

The following example is not made to be pretty or practical, but merely to show an example.

\documentclass{article}
\usepackage{amsmath}
\usepackage{setspace}
\begin{document}
{\setstretch{2.25}
\begin{alignat*}{2}
x(1)   &=\frac{x(0)}{1}    &&= x(0)\\[.5cm]
x(2)   &=\frac{x(1)}{2}    &&= \frac{x(0)}{2}\\[2cm]
x(3)   &=\frac{x(2)}{3}    &&= \frac{x(0)}{2.3}\\[-3mm]
x(4)   &=\frac{x(3)}{4}    &&= \frac{x(0)}{4!}\\
\vdots &                   && \\
x(n)   &=\frac{x(n-1)}{n!} &&= \frac{x(0)}{n!}
\end{alignat*}}
\end{document}


In LyX, I added \usepackage{amsmath} to Document -> Settings -> LaTeX Preamble. Then instead of using array environment, which generates

I change to aligned environment, which generates a much better looking equation array and spacing

There are other discussions on the left alignments that seem very complicated. But what I found in my case is that, if I start a cell with the = sign, the LaTeX compiler will figure out how to align to the left.

• You could achieve a similar result simply by using \displaystyle.
– Alex
Sep 24, 2020 at 7:33