Typing clear and nice-looking solutions to exercises can be a challenge. An example of the way our in-house authors write step-by-step solutions is the following:

The equality signs are nicely aligned, and between every two lines of mathematics, a line with blue text is added to explain the step that has been made. This article will explain exactly how to do this.

The LaTeX structure we need is called an array environment. This will create an array that is centred on the page with a pre-defined number of aligned columns. The way we call it is as follows:

\begin{array}   some code   \end{array}

Note that we don’t need the usual LaTeX delimiters #...# or \[ … \]. Before you can work with your array environment, you must specify, in curly brackets, the number of columns you want it to have. In the example above we have three columns: one for the part to the left of the equality sign, one for the equality sign itself, and one for the part to the right of the equality sign. We also need to specify the alignment of each column. There are three options: l (for left-aligned), c (for centre-aligned), and r (for right-aligned). For the example above, this will look as follows:

\begin{array}{rcl}   some code   \end{array}

This means that our array will have three columns, of which the first is right-aligned, the second is centre-aligned and the third is left-aligned. Now we can start typing the content of the array. Note that we separate the columns by & and we end a row by writing \\. The first line of our example above looks as follows:

If we add all the lines with mathematics, our LaTeX code looks like this:

Note that the array makes the fraction on the third line smaller in order to make every row have the same height. To prevent this, we use the comment \displaystyle just before the fraction, which will make every piece of math in that cell of the array appear in full size.

Lastly, we need to add the blue lines of explanation. To do this, we add another row between every two lines of mathematics, for which the first two columns are empty. This looks as follows:

The additional LaTeX comments that were used are explained below:


generates a horizontal blank space


makes everything between the brackets appear in blue


since ‘array’ is a math environment, we need to use this comment to display text in a normal way

Now you know how to create the example at the beginning of this page in LaTeX! While working on these nice step-by-step solutions, it may happen that your LaTeX output looks like this:

This means that you made a (small) syntax error somewhere in your piece of LaTeX code. This can be many things, like

  • Forgetting a curly bracket or adding one extra;

  • Forgetting to include \end{array};

  • Forgetting to include the column specification {rcl};

If you can’t find the error, try copying and pasting your array line by line to find out in what line the error appears. Another option is to copy and paste your code into a LaTeX editor with syntax correction, like Overleaf. Good luck with the creation of step-by-step solutions!

You can find a general LaTex syntax overview here.

Did this answer your question?