3

I am trying to horizontally align the words "if", as depicted in the image below.

enter image description here

I have tried to use a minipage environment, but this did not yield the desired result. The code for this section of text is shown below.

\documentclass[a4paper,12pt]{extarticle}

\usepackage{graphicx,float}
\usepackage{amsmath}
\usepackage{amsfonts} 
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{mathtools}
\usepackage{float}

\begin{document}
\textit{Case 2}: 
If $s=0$, then 
\[\sum_{r=1}^{N} \exp\left(\frac{2\pi irs}{N}\right)=\sum_{r=1}^{N} 1=N.\] If $s=N$, then 
\[\sum_{r=1}^{N} \exp\left(\frac{2\pi irs}{N}\right)=\sum_{r=1}^{N} \exp (2\pi ir)=\sum_{r=1}^{N} [\cos(2\pi r)+i\sin(2\pi r)]=N.\]
\end{document}

2 Answers 2

4

A simple solution in this case is to use an \hphantom{}:

\hphantom{\textit{Case 2}:}

There are two outcomes, depending on if the initial indent was desired or not:

enter image description here

Notes:

  • Besides \hphantom{} which provides the exact horizontal space as its paramter, there is als \vphantom{} which provides only the vertical spacing (with zero horizontal space). For this case you could also have just used the \phatom{} macro which inserts both the horizontal and vertical spacing of its parameter.

Code:

\documentclass{article}
\usepackage{mathtools}

\begin{document}
\noindent
\textit{Case 2}: 
If $s=0$, then 
\[\sum_{r=1}^{N} \exp\left(\frac{2\pi irs}{N}\right)=\sum_{r=1}^{N} 1=N.\] 
\hphantom{\textit{Case 2}:}
If $s=N$, then 
\[\sum_{r=1}^{N} \exp\left(\frac{2\pi irs}{N}\right)=\sum_{r=1}^{N} \exp (2\pi ir)=\sum_{r=1}^{N} [\cos(2\pi r)+i\sin(2\pi r)]=N.\]

\hrule\medskip\par

\textit{Case 2}: 
If $s=0$, then 
\[\sum_{r=1}^{N} \exp\left(\frac{2\pi irs}{N}\right)=\sum_{r=1}^{N} 1=N.\] 

\hphantom{\textit{Case 2}:}
If $s=N$, then 
\[\sum_{r=1}^{N} \exp\left(\frac{2\pi irs}{N}\right)=\sum_{r=1}^{N} \exp (2\pi ir)=\sum_{r=1}^{N} [\cos(2\pi r)+i\sin(2\pi r)]=N.\]
\end{document}
4
  • This did not appear to work. Are you able to provide the whole code?
    – M B
    Commented Jan 27, 2021 at 8:43
  • @MB: Yeah, I was working on getting the image to include. Commented Jan 27, 2021 at 8:45
  • What a handy command! Thanks for that!
    – M B
    Commented Jan 27, 2021 at 8:46
  • 1
    @MB: Yeah I have used it quite often. I will update the answer to mention the other variants. Commented Jan 27, 2021 at 8:47
4

Do you mean like this?:

\documentclass[a4paper,12pt]{extarticle}

\usepackage{graphicx,float}
\usepackage{amsmath}
\usepackage{amsfonts} 
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{mathtools}
\usepackage{float}

\begin{document}
        
\begin{align*}  
\textit{Case 2}:\quad
&\text{If} s=0, \text{then}
\sum_{r=1}^{N} \exp\left(\frac{2\pi irs}{N}\right)=\sum_{r=1}^{N} 1=N. \\
&\text{If} s=N, \text{then}
\sum_{r=1}^{N} \exp\left(\frac{2\pi irs}{N}\right)=\sum_{r=1}^{N} \exp (2\pi ir)=\sum_{r=1}^{N} [\cos(2\pi r)+i\sin(2\pi r)]=N.
\end{align*}

\end{document}

enter image description here

or

\documentclass[a4paper,12pt]{extarticle}

\usepackage{graphicx,float}
\usepackage{amsmath}
\usepackage{amsfonts} 
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{mathtools}
\usepackage{float}

\begin{document}
        
\begin{align*}  
\textit{Case 2}:\quad
&\text{If}\quad s=0, \text{then}\\
&\sum_{r=1}^{N} \exp\left(\frac{2\pi irs}{N}\right)=\sum_{r=1}^{N} 1=N. \\
&\text{If}\quad s=N, \text{then}\\
&\sum_{r=1}^{N} \exp\left(\frac{2\pi irs}{N}\right)=\sum_{r=1}^{N} \exp (2\pi ir)=\sum_{r=1}^{N} [\cos(2\pi r)+i\sin(2\pi r)]=N.
\end{align*}

\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 .