# Multi-line equations in 'aligned' environment with ampersand (&) inside \left-\right parenthesis

I know how to use the ampersand in align and aligned environments to write multi-line equations. In this case I need to use \left[ and \right] to contain an expression on the first line, and I want the beginning of the second line to be aligned with a specific point inside the square brackets of the first line.

I know from https://www.overleaf.com/learn/latex/Brackets_and_Parentheses that when one wants to use the \left and \right commands on multi-line equations, these commands must be balanced on each line and on the same side of &, and in order to do so one must use "invisible" brackets to balance things out, i.e. adding \right. and/or \left..

So I wrote

\documentclass{article}
\usepackage{amsmath}

\begin{document}

\begin{equation*}
\begin{aligned}
\ddot{Q}_s + 3H\dot{Q}_s + \left[ \frac{k^2}{a^2} \right. & \left. + \mathcal{M}_{SS} + 3\omega^2 - \Pi^2 \right] Q_s \\
&= 4M_P^2\frac{\omega}{\dot{\sigma}}\frac{k^2}{a^2}\Psi - \frac{D}{dt}\left(\Pi_jB^j\right) - \Pi_j\frac{D}{dt}B^j - \mathcal{M}_{Sj}B^j - 3H\left(\Pi_jB^j\right)
\end{aligned}
\end{equation*}

\end{document}


However, as you can see in the figure below, even if the use of \right. and \left. is correct (and in fact this code does not produce errors), the result is disappointing because the right square bracket on the first line have the wrong size. It seems that \left. made the compiler forget the correct size of the left bracket, so that only the text between \left. and \right] is taken into account to evaluate the dimension of the right square bracket. Similarly, it seems that only the text between \left[ and \right. is taken into account to evaluate the dimension of the left square bracket. In other words, it seems that the two square brackets on the first line do not communicate with each other.

How can i fix this? Thank you

• Welcome to TeX.SE! Commented May 7, 2023 at 18:14

You should to try \biggl[ and \biggr] to have symmetrical brackets.

\documentclass[a4paper,12pt]{article}
\usepackage{mathtools,amssymb}

\begin{document}

\begin{equation*}
\begin{aligned}
\ddot{Q}_s & + 3H\dot{Q}_s + \biggl[ \frac{k^2}{a^2} + \mathcal{M}_{SS} + 3\omega^2 - \Pi^2 \biggr] Q_s \\
&= 4M_P^2\frac{\omega}{\dot{\sigma}}\frac{k^2}{a^2}\Psi - \frac{D}{dt}\left(\Pi_jB^j\right) - \Pi_j\frac{D}{dt}B^j - \mathcal{M}_{Sj}B^j - 3H\left(\Pi_jB^j\right)
\end{aligned}
\end{equation*}

\end{document}


• This sure gives the desired result. However, if for example you change k^2/a^2 in only k^2, the brackets will remain of the "bigg" size: the brackets will not rearrange their size depending on the text they contain, and that's just the point of using \right and \left commands... Commented May 8, 2023 at 13:37
• ... this is why I am so interested in understand how this works without have to declare a specific bracket size by hand (like you did) Commented May 8, 2023 at 13:45
• (in my first comment I wrote k^2/a^2, but I meant \frac{k^2}{a^2} obviously...) Commented May 8, 2023 at 13:49
• @Simone Thank you very much for your advices. Commented May 8, 2023 at 19:26
• I'm the one who has to thank you for your quick and effective solution to the problem, I will certainly use your method while waiting to understand if I can actually achieve exactly what I would like to do Commented May 9, 2023 at 8:43

I want the beginning of the second line to be aligned with a specific point inside the square brackets of the first line.

Maybe I'm missing something, but to me the long equation (a) has but one natural line break point -- the second row should start with = -- and (b) no compelling alignment points elsewhere across the two rows. Hence, it looks to me like you'd be better off using a single multline* environment.

\documentclass{article}
\usepackage{amsmath}    % for 'multline*' environment
\usepackage{mleftright} % for '\mleft' and '\mright' macros

\begin{document}

\begin{multline*}
\ddot{Q}_s + 3H\dot{Q}_s + \mleft[ \frac{k^2}{a^2}
+ \mathcal{M}_{SS} + 3\omega^2 - \Pi^2 \mright] Q_s \\
= 4M_P^2\frac{\omega}{\dot{\sigma}}\frac{k^2}{a^2}\Psi
- \frac{D}{dt}(\Pi_jB^j) - \Pi_j\frac{D}{dt}B^j
- \mathcal{M}_{Sj}B^j - 3H(\Pi_jB^j)
\end{multline*}

\end{document}

• However, it seems to me that in this way you cannot choose the exact point in which the lines of the equation alligns... I mean: in the aligned anvironment, using the ampersand &, I can decide where the = with which the second line begins will fall with respect to a certain point of the first line. In your solution, however, it seems like the alignment is automatic, and not to be chosen by the writer. Commented May 8, 2023 at 13:42
• @Simone - Please note that I did not claim that one should not be able to choose the alignment points. What I argued, instead, is that since the equation at hand has an obvious natural break point but (to me at least...) no obvious alignment points, one might as well employ a multline* environment and not waste time on selecting alignment points that might cause the equation to protrude into the margin. Of course, if you believe that I'm wrong and that there are, in fact, suitable candidates for alignment points, then by all means go ahead and exploit this piece of knowledge.
– Mico
Commented May 8, 2023 at 14:37
• I understand that one might use multline environment and not waste time... however, I was interested in writing a multi-line equation in which two aspects are both satisfied: first, I want complete control on where to align the lines (in this example, i want the = of the second line to be aligned with the first + sign inside the square brackets of the first line); second, I want a variable size of the brackets (i.e. if inside the square brackets of the first line I write k^2 instead of \frac{k^2}{a^2}, I would like the size of the brackets to change accordingly). Commented May 8, 2023 at 17:06
• In other words: I want both to be allowed to determine the alignment point, and to have a size of brackets which self-adjust depending on its content, even if there is an ampersand inside. If this cannot be achieved, I will surely use one of the options suggested by you or other users... but nevertheless I am interested to understand if there was a way to do exactly what I would like to do, before looking for other options Commented May 8, 2023 at 17:13