# How do I align equations along operators within parentheses?

Edit 3: See my own answer if you would like to achieve exactly what I was asking for!

Problem
When I put the alignment character (ampersand) inside parentheses, it breaks the compiler.

% !TEX TS-program = pdflatex
\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{array}
\usepackage{amsmath}
\newcommand{\overbar}[1]{\mkern 1.5mu\overline{\mkern-1.5mu#1\mkern-1.5mu}\mkern 1.5mu}
\newcommand{\minus}{\scalebox{0.6}[1.0]{$-$}}

\begin{document}
\resizebox{\linewidth}{!}{ \begin{aligned} \minus\frac{{K_y}_i}{\Delta y^2 \left(1 &+ \frac{K_i^2 \pi^2 \Delta y^2}{12}\right)} \overbar{T}_{i, j-1}\\ \minus\frac{{K_x}_i}{\Delta x^2\! \left(1 - \frac{\pi^2 \Delta x^2}{12}\right)} \overbar{T}_{i-1, j} + 2 \!\left(\! \frac{{K_x}_i}{\Delta x^2 \left(1 - \frac{\pi^2 \Delta x^2}{12}\right)} \!&+\! \frac{{K_y}_i}{\Delta y^2 \left(1 + \frac{K_i^2 \pi^2 \Delta y^2}{12}\right)} \!\right)\! \overbar{T}_{i, j} - \frac{{K_x}_i}{\Delta x^2\! \left(1 - \frac{\pi^2 \Delta x^2}{12}\right)} \overbar{T}_{i+1, j}\\ \minus\frac{{K_y}_i}{\Delta y^2 \left(1 &+ \frac{K_i^2 \pi^2 \Delta y^2}{12}\right)} \overbar{T}_{i, j+1} \end{aligned} =0 }
\end{document}


Details and Research
I would like to arbitrarily align equations so that I can create a "stencil" representation of a nodal matrix to illustrate the process of FDM assembly. When looking through ~7 posts related to alignment, none of them offered the sort of capability I desire.

What I've Tried
I've achieved a workaround by aligning to a point outside the parenthesis and adding a whole bunch of space:

\resizebox{\linewidth}{!}{ \begin{aligned} &\hspace{3em}\minus\frac{{K_y}_i}{\Delta y^2 \left(1 + \frac{K_i^2 \pi^2 \Delta y^2}{12}\right)} \overbar{T}_{i, j-1}\\ \minus\frac{{K_x}_i}{\Delta x^2\! \left(1 - \frac{\pi^2 \Delta x^2}{12}\right)} \overbar{T}_{i-1, j} + 2 &\!\left(\! \frac{{K_x}_i}{\Delta x^2 \left(1 - \frac{\pi^2 \Delta x^2}{12}\right)} \!+\! \frac{{K_y}_i}{\Delta y^2 \left(1 + \frac{K_i^2 \pi^2 \Delta y^2}{12}\right)} \!\right)\! \overbar{T}_{i, j} - \frac{{K_x}_i}{\Delta x^2\! \left(1 - \frac{\pi^2 \Delta x^2}{12}\right)} \overbar{T}_{i+1, j}\\ &\hspace{3em}\minus\frac{{K_y}_i}{\Delta y^2 \left(1 + \frac{K_i^2 \pi^2 \Delta y^2}{12}\right)} \overbar{T}_{i, j+1} \end{aligned} =0 }


I would like a less hacky solution, though.

Thanks so much in advance!

Edit 2: It still hasn't answered my question, but the following improvement will be an easier representation of what I would like to be able to do. I have made the following improvement as per Mico's suggestion. Again, I had to use a workaround, albeit a much cleaner one:

\noindent Let $\kappa_x = \frac{{K_x}_i}{\Delta x^2\! \left(1 - \frac{\pi^2 \Delta x^2}{12}\right)}$ and $\kappa_y = \frac{{K_y}_i}{\Delta y^2 \left(1 + \frac{K_i^2 \pi^2 \Delta y_i^2}{12}\right)}$. Then
\begin{aligned} &\minus\kappa_y \overbar{T}_{i, j-1}\\ \minus\kappa_x \overbar{T}_{i-1, j} + 2 &\left( \kappa_x + \kappa_y \right) \overbar{T}_{i, j} - \kappa_x \overbar{T}_{i+1, j}\\ &\minus\kappa_y \overbar{T}_{i, j+1} \end{aligned} =0

• Welcome :) // Please share the rest of your code, using the Edit button, so we can just copy and run your code. This is also important for us to see, what you include or did not use in your preamble. Thanks May 12 at 17:56
• the answer to your question is to use \bigl( and \bigr) not \left and \right but please never do  \resizebox{\linewidth}{!}{ $ May 12 at 18:10 • @DavidCarlisle I agree that the resizebox hack is gross, but I don't know what else to do to make the equation fit. Do you have a link to a post that I missed that deals with that problem a better way? May 12 at 18:17 • @DavidCarlisle - Also, I hate to say it, but I like the way \left and \right look a lot better. May 12 at 19:30 • @mcmuffin6o \left ad \right produce unwanted horizontal space so it is usually better to choose a fixed size ayway, but in an aligment they are not available anyway. Of course \bigl was just an option, choose a suitabbl size \Biggl( or whatever, there is no reason why \left\right should look better than a manually chosen size. May 12 at 20:13 ## 3 Answers Remark: I thoroughly updated this answer after learning from the OP what the (to me) unusual cruciform layout of the five additive terms across three lines was meant to signify. The following one-line equation should be easy to grasp for your readers. (Note that I've multiplied the terms on the left hand side by -1, which is permissible since their sum equals 0.) With this setup, do take a sentence or two to explain the ordering of elements in terms of items involving T_{.,j-1}, T{.,j}, and T_{.,j+1. \documentclass[11pt]{article} \let\overbar\overline % ? \begin{document} Set$\kappa_x={K_x}_i\big/\bigl[\Delta x^2(1-\pi^2)/12\bigr]$and$\kappa_y={K_y}_i\big/\bigl[\Delta y^2(1+K_i^2\pi^2 )/12\bigr]. Then $$\kappa_y \overbar{T}_{i,j-1} + \kappa_x \overbar{T}_{i-1,j} - 2(\kappa_x + \kappa_y) \overbar{T}_{i,j} + \kappa_x \overbar{T}_{i+1,j} + \kappa_y \overbar{T}_{i,j+1} =0$$ \end{document}  • Thanks for the answer, Mico! You are absolutely correct that putting the equation on three lines is the optimal solution if there is no spatial/shape constraint. Unfortunately, I need that cross layout, since the equation is a "stencil" that is used in the assembly of the global FDM matrix. I will certainly use your excellent suggestion of creating and using a \kappa, however! I would upvote your solution if I had the reputation :) Oop, I just hit 20 rep, upvoted!!! May 12 at 18:50 • @mcmuffin6o - Glad you like the variable substitution idea. I guess that what has me most confused by your layout choice is that the =0 term seems to pertain to just the middle row, begging the question of what the terms in rows 1 and 3 pertain to. – Mico May 12 at 19:13 • Ah, I see how it could be confusing without context. I'm certain that given the preceding context of the document and the course that this is being written for, it will be understood. It's a stencil for the construction of a global FDM matrix. May 12 at 19:16 • "upon learning from the OP that what they are trying to typeset is an equation in which a 3x1 column vector equals zero" - this is incorrect. It's just a scalar equation that is formatted a certain way. May 13 at 2:57 • However, that does bring up the good point that I should indeed not use pmatrix. May 13 at 3:05 I think that the other options discussed here look much better and are significantly more readable, but if you are using LuaLaTeX and really want to do such odd alignments you can use my luamathalign package. It introduces an \AlignHere macro which acts like & except that it doesn't have all these pesky limitations about where it can't appear: Just load luamathalign and replace every problematic & with \AlignHere. % !TEX TS-program = lualatex \documentclass{article} \usepackage{unicode-math,luamathalign} \begin{document} \begin{aligned} \minus\frac{{K_y}_i}{\Delta y^2 \left(1 \AlignHere+ \frac{K_i^2 \pi^2 \Delta y^2}{12}\right)} \overbar{T}_{i, j-1}\\ \minus\frac{{K_x}_i}{\Delta x^2\! \left(1 - \frac{\pi^2 \Delta x^2}{12}\right)} \overbar{T}_{i-1, j} + 2 \!\left(\! \frac{{K_x}_i}{\Delta x^2 \left(1 - \frac{\pi^2 \Delta x^2}{12}\right)} \!\AlignHere+\! \frac{{K_y}_i}{\Delta y^2 \left(1 + \frac{K_i^2 \pi^2 \Delta y^2}{12}\right)} \!\right)\! \overbar{T}_{i, j} - \frac{{K_x}_i}{\Delta x^2\! \left(1 - \frac{\pi^2 \Delta x^2}{12}\right)} \overbar{T}_{i+1, j}\\ \minus\frac{{K_y}_i}{\Delta y^2 \left(1 \AlignHere + \frac{K_i^2 \pi^2 \Delta y^2}{12}\right)} \overbar{T}_{i, j+1} \end{aligned} =0 \end{document}  • Thanks @Marcel! I will keep this in mind if I ever reconsider compiler options. May 12 at 20:31 • @Mico Thanks, fixed that. May 12 at 20:36 • +1. Nice use of the luamathalign package! – Mico May 12 at 20:51 Edit 2: See the bonus solution to be able to to exactly what the original question asked! Welp, it turns out I should have more deeply considered one of the other posts I saw relating to just putting stuff in a matrix. If I do the following, it aligns perfectly and is clearer that the entirety of the terms are equal to zero. Credit to @Mico for leading me to this answer! \noindent Let\kappa_x = \frac{{K_x}_i}{\Delta x^2\! \left(1 - \frac{\pi^2 \Delta x^2}{12}\right)}$and$\kappa_y = \frac{{K_y}_i}{\Delta y^2 \left(1 + \frac{K_i^2 \pi^2 \Delta y_i^2}{12}\right)}$. Then $$\begin{pmatrix} \minus\kappa_y \overbar{T}_{i-1, j}\\ \minus\kappa_x \overbar{T}_{i, j-1} + 2 \left( \kappa_x + \kappa_y \right) \overbar{T}_{i, j} - \kappa_x \overbar{T}_{i, j+1}\\ \minus\kappa_y \overbar{T}_{i+1, j} \end{pmatrix} =0$$  Which results in the following: Now that I think about it, if I didn't want the parenthesis, I could even do the following: \noindent Let$\kappa_x = \frac{{K_x}_i}{\Delta x^2\! \left(1 - \frac{\pi^2 \Delta x^2}{12}\right)}$and$\kappa_y = \frac{{K_y}_i}{\Delta y^2 \left(1 + \frac{K_i^2 \pi^2 \Delta y_i^2}{12}\right)}. Then $$\begin{matrix} \minus\kappa_y \overbar{T}_{i-1, j}\\ \minus\kappa_x \overbar{T}_{i, j-1} + 2 \left( \kappa_x + \kappa_y \right) \overbar{T}_{i, j} - \kappa_x \overbar{T}_{i, j+1}\\ \minus\kappa_y \overbar{T}_{i+1, j} \end{matrix} =0$$  Which would result in the following: Edit: Bonus solution! (Which happens to be the answer closest to the original question) In case you do indeed something tall with \left and \right (which I ended up not needing), Just open and close the right and left around the alignment operator and add a \vphantom{<something with the same height as what you want your brackets/braces/parenthesis to be>}: \noindent Let\kappa_x = \frac{{K_x}_i}{\Delta x^2\! \left(1 - \frac{\pi^2 \Delta x^2}{12}\right)}$and$\kappa_y = \frac{{K_y}_i}{\Delta y^2 \left(1 + \frac{K_i^2 \pi^2 \Delta y_i^2}{12}\right)}\$. Then
\begin{aligned} \minus\kappa_y &\overbar{T}_{i, j-1}\\ \minus\kappa_x \overbar{T}_{i-1, j} + 2 \left(\kappa_x \vphantom{\kappa_x} \right. &+ \left.\vphantom{\kappa_y} \kappa_y\right) \overbar{T}_{i, j} - \kappa_x \overbar{T}_{i+1, j}\\ \minus\kappa_y &\overbar{T}_{i, j+1} \end{aligned} =0
`