2

I'm trying to write "T(n/3)" within an align block, but I'm not getting the behavior I expect. When I enter this:

\documentclass{article}
\usepackage[utf8]{inputenc}

\begin{document}

\begin{align}

    T(n) = 3T(\frac{n}{3}) + 2n -3

\end{align}

\end{document}

I get this output from Overleaf:

Everything after the \frac gets put in the denominator of the fraction

I didn't get this issue when I used aligns and fracs before in the same document. For example, this one worked just as intended:

\begin{align}
S &= \frac{1}{2} + &\frac{1}{4} + &\frac{2}{8} +&\frac{3}{16} + &\frac{5}{32} + &\frac{8}{64} + &\frac{13}{128} + \dots\\
\frac{1}{2}S &= &\frac{1}{4} + &\frac{1}{8} + &\frac{2}{16} +&\frac{3}{32} + &\frac{5}{64} + &\frac{8}{128} + \dots\\
S-\frac{1}{2}S &= \frac{1}{2}+ &\frac{0}{4} + &\frac{1}{8} + &\frac{1}{16} +&\frac{2}{32} + &\frac{3}{64} + &\frac{5}{128} + \dots\\
&= \frac{1}{2} + \frac{S}{4}\\
&\implies 4S-2S=2+S\\
&\implies S=2
\end{align}

yielding:

\frac in align that works properly

  • I cannot reproduce your behavior with the syntax you provide. – Steven B. Segletes Oct 04 '19 at 14:48
  • Welcome to TeX.SX! Please help us help you and add a minimal working example (MWE) that illustrates your problem. Reproducing the problem and finding out what the issue is will be much easier when we see compilable code, starting with \documentclass{...} and ending with \end{document}. – Alessandro Cuttin Oct 04 '19 at 14:56
  • 1
    @AlessandroCuttin I added one, thanks for letting me know – Joseph Feld Oct 04 '19 at 15:03
  • @StevenB.Segletes I added a MWE to make it easier to run – Joseph Feld Oct 04 '19 at 15:04
  • 3
    if you get an error please ask about the error (by design the typeset pdf is essentially nonsense after any error so showing the printed output is not so useful) If you scroll past an error tex's recovery aims to help debugging but makes no attempt at sensible output. – David Carlisle Oct 04 '19 at 15:18
  • As stated in the answer by @AlessandroCuttin align is part of the amsmath package so you need \usepackage{amsmath}. Also, remove the empty lines inside the align environment. An empty line is a new paragraph, which is not appreciated in mathmode. – StefanH Oct 04 '19 at 17:11
  • I can reproduce the output by only adding \usepackage{amsmath} and skipping errors. Of course, the issue are the blank lines inside align, that are not allowed and raise low level errors. – egreg Nov 03 '19 at 16:07

1 Answers1

1

What about the following?

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}

\begin{document}
    \begin{align}
        S &= \frac{1}{2} + &\frac{1}{4} + &\frac{2}{8} +&\frac{3}{16} + &\frac{5}{32} + &\frac{8}{64} + &\frac{13}{128} + \dots\\
        \frac{1}{2}S &= &\frac{1}{4} + &\frac{1}{8} + &\frac{2}{16} +&\frac{3}{32} + &\frac{5}{64} + &\frac{8}{128} + \dots\\
        S-\frac{1}{2}S &= \frac{1}{2}+ &\frac{0}{4} + &\frac{1}{8} + &\frac{1}{16} +&\frac{2}{32} + &\frac{3}{64} + &\frac{5}{128} + \dots\\
        &= \frac{1}{2} + \frac{S}{4}\\
        &\implies 4S-2S=2+S\\
        &\implies S=2\\
        T(n) &= 3T\left(\frac{n}{3}\right) + 2n -3
\end{align}
\end{document}

with respect to your MWE I added the amsmath package, and improved the brackets by using \left and \right, which gives me:

enter image description here