# Array size of things

I have the following code:

\documentclass[12pt]{article}
\usepackage{mathtools}
\begin{document}
$$\begin{array}{cl} f(\hat{x}_n) & =\displaystyle \int_{-1}^{0} \hat{x}_n d t - \int_{0}^{1} \hat{x}_n d t \\ & = \displaystyle \int_{-1}^{-\frac{1}{n+1}} d t +\int_{-\frac{1}{n+1}}^{0} -(n+1)t d t +\int_{0}^{\frac{1}{n+1}} (n+1)t d t +\int_{\frac{1}{n+1}}^{1} d t \\ & =\frac{n}{n+1} +\frac{n}{2n+21} +\frac{n}{2n+2} +\frac{n}{n+1} \\ & = \frac{2n+1}{n+1} \end{array}$$
\end{document}


This gave me the following:

And this very ugly, the size of the fractions is too small, if I change it they overlapse, the same space of the lines is very small for the integrals to look good. How can I improve this?

• You could use an align environment. Oct 27, 2020 at 20:32
• note that  is not latex (use $..$) the array environment is designed for arrays/matrices of values not for displayed equations so they are set in textsyle and the spacing is all wrong, which is why you are needing to ty to correct with \displaystyle but better to use a display environment such as align (or aligned for a term within a larger display) Oct 27, 2020 at 20:34

With align for numbered lines and align* for unnumbered lines:

\documentclass[12pt]{article}
\usepackage{mathtools}
\begin{document}
\begin{align}
f(\hat{x}_n) & = \int_{-1}^{0} \hat{x}_n d t  - \int_{0}^{1} \hat{x}_n d t  \\
& = \int_{-1}^{-\frac{1}{n+1}} d t   +\int_{-\frac{1}{n+1}}^{0} -(n+1)t d t
+\int_{0}^{\frac{1}{n+1}} (n+1)t d t  +\int_{\frac{1}{n+1}}^{1} d t \\
& =\frac{n}{n+1} +\frac{n}{2n+21} +\frac{n}{2n+2}  +\frac{n}{n+1} \\
& = \frac{2n+1}{n+1}
\end{align}

\begin{align*}
f(\hat{x}_n) & = \int_{-1}^{0} \hat{x}_n d t  - \int_{0}^{1} \hat{x}_n d t  \\
& = \int_{-1}^{-\frac{1}{n+1}} d t   +\int_{-\frac{1}{n+1}}^{0} -(n+1)t d t
+\int_{0}^{\frac{1}{n+1}} (n+1)t d t  +\int_{\frac{1}{n+1}}^{1} d t \\
& =\frac{n}{n+1} +\frac{n}{2n+21} +\frac{n}{2n+2}  +\frac{n}{n+1} \\
& = \frac{2n+1}{n+1}
\end{align*}
\end{document}