2

I have the following equations:

enter image description here

Now I want to shift the $2^{2k}$ and $2^k$ in the last three lines to the right, just before the $\geq$ sign. How can I achieve that without hardcoding?

Here is my MWE:

\documentclass[ngerman, fontsize=11pt, DIV=12 ,BCOR = 10mm, parskip=half-, twoside]{scrbook}

\usepackage{amsmath}

\begin{document} \begin{alignat}{2} &2^k\cdot (2^k-h)&&\geq 1 \ \Longleftrightarrow &2^{2k}-h\cdot 2^k&&\geq 1 \ \Longleftrightarrow &2^{2k}&&\geq h\cdot 2^k+1 \ \Longleftrightarrow &2^k &&\geq \sqrt{h\cdot 2^k+1} \ \Longleftrightarrow &2^k &&\geq \sqrt{n}. \end{alignat} \end{document}

When I change 2^{2k}& to &2^{2k} I get additional space in the frst two lines.

enter image description here

Lereu
  • 449
  • 1
    change 2^{2k}& to &2^{2k}, also you want \Longleftrightarrow{} to get the correct spacing back if you have the arrow to the left of the & – David Carlisle Jan 15 '24 at 17:44

2 Answers2

3

You want the expressions in an odd (right aligned) column.

enter image description here

\documentclass[ngerman, fontsize=11pt, DIV=12 ,BCOR = 10mm, parskip=half-, twoside]{scrbook}

\usepackage{amsmath}

\begin{document} \begin{alignat}{2} &&2^k\cdot (2^k-h)&\geq 1 \ &\Longleftrightarrow &2^{2k}-h\cdot 2^k&\geq 1 \ &\Longleftrightarrow &2^{2k}&\geq h\cdot 2^k+1 \ &\Longleftrightarrow &2^k &\geq \sqrt{h\cdot 2^k+1} \ &\Longleftrightarrow &2^k &\geq \sqrt{n}. \end{alignat} \end{document}

David Carlisle
  • 757,742
  • Thank you, I guess I can use that. One more question: In your code, can I align the first two lines, so that 2^k in the first line and 2^{2k} in the second line are aligned? So that there is no space before 2^{2k}? – Lereu Jan 15 '24 at 17:51
  • @Lereu you can but I wouldn't: just add another && at that point just keep in mind that odd columns align right and even columns align left – David Carlisle Jan 15 '24 at 18:21
  • @Lereu: ...replace amsmath with mathtools (it loads amsmath, but adds other functionality) and then use \mathrlap{2^{2k} - h \cdot 2^k}\phantom{2^k \cdot (2^k - h)}. – Werner Jan 15 '24 at 18:22
3

I wouldn't try and align things that are just very loosely related.

I give you three realizations. The section titles should self-explain my recommendation.

\documentclass{article}
\usepackage{amsmath}

\begin{document}

\section{Good}

\begin{align} & 2^k\cdot (2^k-h)\geq 1 \ \Longleftrightarrow\quad & 2^{2k}-h\cdot 2^k\geq 1 \ \Longleftrightarrow\quad & 2^{2k}\geq h\cdot 2^k+1 \ \Longleftrightarrow\quad & 2^k \geq \sqrt{h\cdot 2^k+1} \ \Longleftrightarrow\quad & 2^k \geq \sqrt{n}. \end{align}

\section{Bad (well, not so much)}

\begin{alignat}{2} &&2^k\cdot (2^k-h)&\geq 1 \ &\Longleftrightarrow\quad &2^{2k}-h\cdot 2^k&\geq 1 \ &\Longleftrightarrow\quad &2^{2k}&\geq h\cdot 2^k+1 \ &\Longleftrightarrow\quad &2^k &\geq \sqrt{h\cdot 2^k+1} \ &\Longleftrightarrow &2^k &\geq \sqrt{n}. \end{alignat}

\section{Ugly}

\begin{alignat}{3} & 2^k&{}\cdot (2^k-h)&\geq 1 \ \Longleftrightarrow\quad & 2^{2k}&{}-h\cdot 2^k&\geq 1 \ \Longleftrightarrow\quad &&2^{2k}&\geq h\cdot 2^k+1 \ \Longleftrightarrow\quad &&2^k &\geq \sqrt{h\cdot 2^k+1} \ \Longleftrightarrow\quad &&2^k &\geq \sqrt{n}. \end{alignat}

\end{document}

enter image description here

Actually, I'd use gather* with no \Longleftrightarrow, explaining that each line implies the following and is implied by the preceding one.

enter image description here

egreg
  • 1,121,712
  • Thank you, I can learn from your code. Nevertheless, I would exactly swap 1) and 3). But this is a matter of taste. – Lereu Jan 15 '24 at 18:20
  • @Lereu There is a fourth realization, which I added only the picture of, with some explanation. – egreg Jan 15 '24 at 20:42