0
f(n) = \begin{cases} n/2 &\mbox{if } n \equiv 0 \\
(3n +1)/2 & \mbox{if } n \equiv 1 \end{cases}

I read somewhere that in the cases environment it doesn't require $ and when I do try and put $, it says I am still missing it. I am fairly new to Latex and quite confused.

\documentclass[12pt, letterpaper]{article} 
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{amssymb}
\setlength{\parindent}{0pt}

\title{}
\author{} 
\date{} 

\begin{document} 
\maketitle
\begin{tabbing}

\underline{\textbf{Problem 13.}} \\

f(n) = \begin{cases} n/2 &\mbox{if } n \equiv 0 \\
(3n +1)/2 & \mbox{if } n \equiv 1 \end{cases}

\end{tabbing}
\end{document}
7
  • Welcome to text.stackexchange.com. Since you seemingly are familiar with the basics of coding, you better present your problem in a full document layout with documentclass, etc. in order to reproduce the error you got so that the others can help you.
    – Diaa
    Apr 11, 2020 at 2:54
  • Okay, I posted my whole code, but it runs fine once I remove the cases environment
    – Dafeon
    Apr 11, 2020 at 3:00
  • 1
    Welcome to TeX.SX. please read an introduction to LaTeX before moving any further.
    – Johannes_B
    Apr 11, 2020 at 3:02
  • 2
    The line with \begin{cases} is almost at the end of the file. The cases environment itself must be in math mode, and it isn't. Add $ at each end, as $\begin{cases} ... \end{cases}$. Apr 11, 2020 at 3:10
  • 4
    You probably want \[ f(n) = \begin{cases}... \end{cases} \] so that the equation is displayed.
    – user30471
    Apr 11, 2020 at 4:10

1 Answer 1

1

In relation by comments of the very good users I add a MWE. I have delete \setlength{\parindent}{0pt} and I have added the package \usepackage{parskip} with the same function, \text{if } instead of \mbox{if }.

\documentclass[12pt,letterpaper]{article} 
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{parskip}
\title{}
\author{} 
\date{\today} 

\begin{document} 
\maketitle
\begin{tabbing}
\underline{\textbf{Problem 13.}} \\
$f(n) = \begin{cases} n/2 &\text{if } n \equiv 0 \\
(3n +1)/2 & \text{if } n \equiv 1 \end{cases}$
\end{tabbing}
\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 .