4

I'm writing an equation that I want to be aligned roughly like this:

-1 ≤   Re z ≤ 1
-2 ≤ 2 Re z ≤ 2

I tried this code, but it doesn't seem to work:

\renewcommand{\Re}[1]{\,\mathrm{Re}\,{#1}}

\begin{align*}
-1 \leq & \Re{z}  &\leq 1 \\
-2 \leq & 2\Re{z} &\leq 2
\end{align*}

output of the code


How can I get it to look like what I showed?

2
  • use && before the last part so it is left aligned, also please always post a complete document not just a fragment. Nov 19, 2020 at 22:15
  • @DavidCarlisle Hmm, that didn't work for me. I had to use alignat* as Werner suggested.
    – Camelid
    Nov 19, 2020 at 22:22

2 Answers 2

4

With multiple alignment points within the same construction, it's best to use alignat (and friends):

enter image description here

\documentclass{article}

\usepackage{amsmath}

\begin{document}

\begin{alignat*}{2}
  -1 \leq {}&&  \Re{z} & \leq 1 \\
  -2 \leq {}&& 2\Re{z} & \leq 2
\end{alignat*}

\end{document}
3
  • Thanks! That fixed it. By the way, if I want to add a bit more space after the first ≤ should I just use \; or something? Currently it looks like i.sstatic.net/SLFNv.png because I overrode the \Re command.
    – Camelid
    Nov 19, 2020 at 22:20
  • 1
    @Camelid: Note the use and location of {} in my code.
    – Werner
    Nov 19, 2020 at 22:22
  • Oh, I didn't realize that {} added spacing. Thanks so much for your help!
    – Camelid
    Nov 19, 2020 at 22:24
5

Column pairs in align are separated by a wide blank space. You need alignat, but it's not really easy to take care of the necessary tricks.

I find it more convenient to use array for this application.

Note that your redefinition of \Re is not the best.

\documentclass{article}
\usepackage{amsmath,array}

\renewcommand{\Re}{\operatorname{Re}}

\begin{document}

\begin{alignat*}{3}
-1 &\leq{} &  \Re z &\leq 1 \\
-2 &\leq{} & 2\Re z &\leq 2
\end{alignat*}

\begin{equation*}
\setlength{\arraycolsep}{0pt}
\renewcommand{\arraystretch}{1.2}
\begin{array}{r >{{}}c<{{}} r >{{}}c<{{}} r}
-1 &\leq&  \Re z &\leq& 1 \\
-2 &\leq& 2\Re z &\leq& 2
\end{array}
\end{equation*}

\end{document}

enter image description here

With >{{}}c<{{}} we reserve a column for the relation symbols, suitably spaced because of the empty items around them.

5
  • Ah, thanks for the tip re \Re :)
    – Camelid
    Nov 19, 2020 at 22:27
  • By the way, what do you mean by "You need alignat, but it's not really easy to take care of the necessary tricks."? I found that it seems to work quite well.
    – Camelid
    Nov 19, 2020 at 22:28
  • 1
    @Camelid You need to suitably apply {} in not easy to predict (for a beginner) places; and controlling the alignment is not easy either; with array you have more choices.
    – egreg
    Nov 19, 2020 at 22:29
  • Ah, I see what you mean. I think I saw some people say you shouldn't use array since it's not semantically correct, but I guess using alignat can be annoying enough that array is sometimes worth it?
    – Camelid
    Nov 19, 2020 at 23:04
  • @Camelid The name array doesn't imply matrices are necessarily involved, just alignments.
    – egreg
    Nov 19, 2020 at 23:17

You must log in to answer this question.

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