TransWikia.com

How do you do a "staircase align" in Latex?

TeX - LaTeX Asked by Procyonic on May 29, 2021

I want to create something like

enter image description here

or

enter image description here

where the = is aligned with the last character of the previous equation. But I’m not sure how to make this work.

I’ve tried,

begin{align} a = b &  
                    & = c & 
                          & = d  end{align}

But this doesn’t give me what I want

3 Answers

documentclass{article}
usepackage{amsmath}
begin{document}
begin{alignat}{2}
a = b & && 
                  & {}= c &&
                  &     &{} = d &
                  &     &      &{} = e 
end{alignat}
end{document}

enter image description here

Correct answer by Steven B. Segletes on May 29, 2021

You could use an array environment.

documentclass{article}
usepackage{amsmath}
begin{document}
[ begin{array}{*5{l@{;}}}
    a = & b 
        & = & c 
        &   & = & d 
        &   &   & = & e
end{array} ]
end{document}

Answered by Vincent on May 29, 2021

You can use alignat, but it's handier if we don't have to compute the number of necessary &'s and let TeX do it.

The main left-hand side is given as argument to the environment, the rest is in the environment, lines separated by .

documentclass{article}
usepackage{amsmath}

ExplSyntaxOn

NewDocumentEnvironment{staircase}{mb}
 {
  procyonic_staircase:nnn { } { #1 } { #2 }
 }
 {}
NewDocumentEnvironment{staircase*}{mb}
 {
  procyonic_staircase:nnn { * } { #1 } { #2 }
 }
 {}

cs_new_protected:Nn procyonic_staircase:nnn
 {
  seq_set_split:Nnn l__procyonic_staircase_seq {  } { #3 }
  begin{alignat#1}{ int_eval:n { seq_count:N l__procyonic_staircase_seq + 1 } }
  #2 ={} &
  seq_map_indexed_function:NN l__procyonic_staircase_seq __procyonic_staircase:nn 
  end{alignat#1}
 }

seq_new:N l__procyonic_staircase_seq

cs_new_protected:Nn __procyonic_staircase:nn
 {
  prg_replicate:nn { #1*2 } { & }
  int_compare:nF { #1 = 1 } { negthickspace = }
  #2
  int_compare:nF { #1 = seq_count:N l__procyonic_staircase_seq } {  }
 }

ExplSyntaxOff

begin{document}

begin{staircase}{a}
 b  c  d
end{staircase}

begin{staircase*}{a}
 b  c  d
end{staircase*}

end{document}

enter image description here

Answered by egreg on May 29, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP