2

NB: In the original version of this post, I mistakenly used "vertical alignment" where I really should have used "horizontal alignment" instead. I have now corrected this mistake throughout. After this correction, however, I can no longer say that what I describe in this post really holds. My vertical/horizontal mixup could have easily explained all my difficulties with this topic.


As I've explained elsewhere1, mastering LaTeX has a crowning position among my professional failures.

And, within the topic of LaTeX, the subtopic of horizontal alignment of multiline mathematical expressions, holds, in turn, the place of honor, for the most hours wasted in futility and frustration.

I think an explanation for this may be, in part, the seemingly inexhaustible number of approaches (including, "vanilla LaTeX" directives, packages, recipes, hacks, etc.) to solving some very narrowly circumscribed subvariant of the horizontal alignment problem. As a result, every time I attempt to solve some particular horizontal alignment problem, my online searches turn up a huge number of approaches, all completely different from each other, and none suitable to what I am trying to do2.

Therefore, I think that what I need to do is study a comprehensive treatise on this problem: one that surveys the largest possible3 number of approaches to the horizontal alignment problem.

Does anyone know of such a treatise? If so, please point me to it.


EDIT: If an example of what I am referring to is needed, below is the sort of thing I am reduced to having to do to get a horizontal alignment among the various elements of two mathematical expression that approaches what looks right to me:

\begin{align*}
\hspace{3cm}&\exists\,w\,&&\hspace{-1.4cm}[\,w&\hspace{-1.3cm}\in{P}\;&\wedge&&\hspace{-1.3cm}wTy\,&\hspace{-1.4cm}]\;&\text{,\hspace{10pt}and}\\
\hspace{3cm}&\exists\,z\,&&\hspace{-1.4cm}[\,z&\hspace{-1.3cm}\in{P}\;&\wedge&&\hspace{-1.3cm}xTz\,&\hspace{-1.4cm}]\;&.
\end{align*}

The idiotic game of figuring out the values for the \hspace's took me about 1 hour. I hope this spells out "PATHETIC FAILURE" sufficiently clearly.

Of course, the experience above would make it clear to anybody that, despite the word "align" conspicuously featured in this approach, \begin{align*}...\end{align*} is just not the right one for this particular problem. The only excuse for me to continue using it goes along the lines of "better the devil you know, than the 10K angel-wannabes you don't."


1 See footnote 3 of makecell: how to reduce the line spacing in multiline cells?

2Obviously, the latter description is an exaggeration. Where I wrote "none suitable", I mean "none (within the limits of my stamina) suitable". I am sure that within the top, say, 100 search results, I probably would be able to find a solution that does what I need, but after fighting fruitlessly with the recipes proposed in the first 6 or 7 hits, I begin to run out of steam.

3Again, I exaggerate for the sake of simplicity. I realize that, between the time that someone begins to write such a treatise, and the time of its publication, dozens of entirely new approaches to horizontal alignment would have seen the light of day, so the goal of comprehensiveness should be construed as an ideal to strive for, despite being unattainable.


PS: @DavidCarlisle is is right that, as examples go, the one I posted is (still) unreasonably unhelpful. I had my own tortured reason for doing this. Unfortunately, it is, as they say complicated. In the unlikely event that anyone cares to know the tedious details, see below.

tl;dr: The fact that I posted an example at all is an instance of the good intentions that infamously pave the Road to Hell... You see, originally, I wanted the answer to my question to be a pointer to study material that I could read to finally understand in as much generality as possible the problem of using LaTeX to position elements in multiline mathematical expressions so that they line up vertically.

Given this fairly clear initial goal, in the original version of my post, I consciously refrained from providing examples, because I knew that, no matter how clearly and unambiguously the rest of my post described my goal, the presence of an example would immediately send a very strong, but completely counterpurpose, signal, namely that my post was, not a request for study material on LaTeX, but about how to solve the problem illustrated by the example.

I know from experience, however, that, in general, many readers resent questions pitched at the level of generality of my post's original version, so I was not surprised to see that a request for such an example appeared not long after I posted my question.

To make matters much worse for this particular case, the terminology I used in the original version was exactly backwards (or rather orthogonal 🙂): I was using the term "vertical alignment" to refer to what is commonly known as "horizontal alignment."

This really unfortunate mixup, coupled with the question's original generality, made it admittedly difficult to understand, even to anyone willing to engage with a question pitched at such level of generality.

At any rate, against my better judgment, I eventually gave in to a request for an example, knowing full well that said example would almost certainly completely eclipse the original question. In order to reduce this risk, however, along with the example, I included accompanying commentary to emphasize that this example meant to illustrate, through the obvious perversity of the LaTex code in it, that I really was hopelessly lost when it came to solving with such alignment problems, and that only a very thorough, from-the-ground-up treatment could address ignorance of this magnitude.

Furthermore, to keep the focus on the code's cluelessness, I consciously omitted an image of the desired output. To have included such an image would have, again, reinforced the counterpurpose message I was trying to dial down.

As it happens, it appears that it was through this unanimously unloved little example that @user202729 figured out that I was using the wrong terminology. This is no small matter, since I have no doubt that my confusion on terminology thorougly sabotaged all attempts to find solutions to these problems through Google. At the very least, learning about my mixup got me to straightening out the post's wording. Therefore, in this case, my providing an example had benefits I had not foreseen.

Also, even though @DavidCarlisle's reply illustrates the kind that all my machinations were aiming to discourage, I admit that I found it very helpful and instructive. So I am thankful to him for working past the obstacles I put in his way.

In fact, don't think it is excessively optimistic to think that the combination of finally learning the correct terminology, together with @DavidCarlisle's solution to my (yes, thoroughly misbegotten) example will allow me to handle many of the alignment problems that have confounded me so far.

14
  • 1
    Let's see... obviously you can do everything with halign. TeX has array (math mode) and tabular (basically the same thing in text mode) which wraps over it, so you should be able to do everything just with array. (and learn about classes of mathematical objects) Do you already know how to use that? alignat and other math environments are just "convenient wrappers" over that (which supports e.g. automatic numbering), but you can do the alignment part alone without.
    – user202729
    Commented Jun 11, 2022 at 14:12
  • 1
    you only posted a fragment rather than a test document and didn't show the output or say what you wanted, which makes it harder than it should be to undersand your question but your fragment markup looks very strange, I would start by removing all \hspace and \, then see about adjusing the default layout to meet your needs without complicating explicit spaces everywhere. Commented Jun 11, 2022 at 14:38
  • 1
    If I use your fragment with default fonts I get this output Do you mean you_want_ this over printing? It seems very strange to me but you are explicitly forcing that, there is no way LateX is going to automatically make such a layout. Commented Jun 11, 2022 at 14:45
  • 1
    @kjo that is why you should have posted a document or at least an image, it was quite hard to guess the intended layout at all from the mess of over printed symbols your fragment makes with the default fonts. However that should never be an issue in practice as there is never a need to add such space commands. If you find yourself tempted to add cm spaces or negative spaces, stop and consider an alternative. Commented Jun 11, 2022 at 16:02
  • 2
    I am admittedly biased, but had I seen this question when it was asked, I would have, in turn, asked if you had looked at the user's guide for amsmath (texdoc amsldoc'). If you had, but found nothing useful, and could be more precise about what you were looking for, that would have given a more useful focus for potential helpers to address. Commented Jun 11, 2022 at 19:41

1 Answer 1

3

If using multiple alignment points within a single expression, it's usually better to use alignat rather than align as the latter is designed for aligning multiple columns of equations and adds additional space.

Also avoid adding explicit space, If you do need to add space use math spaces such as \, or \mspace{5mu} which are compatible with the math spacing. Using fixed units such as cm will typically produce bad layout and over-printing as your fragment shows.

Here I just use left aligned columns of an alignat (hence && to skip the right aligned cells)

\documentclass{article}

\usepackage{mathtools}

\begin{document}

\begin{align*}
\hspace{3cm}&\exists\,w\,&&\hspace{-1.4cm}[\,w&\hspace{-1.3cm}\in{P}\;&\wedge&&\hspace{-1.3cm}wTy\,&\hspace{-1.4cm}]\;&\text{,\hspace{10pt}and}\\
\hspace{3cm}&\exists\,z\,&&\hspace{-1.4cm}[\,z&\hspace{-1.3cm}\in{P}\;&\wedge&&\hspace{-1.3cm}xTz\,&\hspace{-1.4cm}]\;&.
\end{align*}

\begin{alignat*}{-1}
  \exists w &\,[ w\in P  &&\wedge w &&\mathbin{T}y &&]&&\text{, and} \\
  \exists z &\,[ z\in P  &&\wedge w &&\mathbin{T}z &&]&&\text{.} 
\end{alignat*}
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .