# Cannot properly format an algorithm

I need to place an algorithm inside my text. However, it keeps being displayed incorrectly. Could you take a look at the LaTeX code and help me find where I am going wrong?

This is the code I'm currently using:

\documentclass[12pt,oneside,a4paper,brazil]{report}

\usepackage{algorithm}
\usepackage{float}
\usepackage{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage[noend]{algpseudocode}
\newcommand\BB{BB}

\begin{document}
\begin{algorithm}
\caption{The \BB algorithm}
\begin{algorithmic}
\State \BB(G, Q, K)
\State $\text{C} \gets \text{Q}$
\If {$\text{K} \neq \emptyset$ }
\State $\text{v} \gets \text{a vertex in K}$
\State ${C_1 \gets BB(G, Q \cup \{v\}, U \cap \Gamma_G(v))$
\If {$|C_1| > |C|$}
\State $C \gets C_1$
\EndIf
\State $C_2 \gets BB(G, Q, K - v)$
\If {$|C_2| > |C|$}
\State $C \gets C_2$
\EndIf
\EndIf
\Return $C$
\end{algorithmic}
\end{algorithm}

\end{document}


Any help will be much appreciated.

• Welcome to TeX SX! What exactly is the problem? A full compilable code also would help to help. You seem to be using babel-italian? – Bernard Nov 1 '16 at 11:44
• Thank you! I'm fairly new to the LaTeX platform. \documentclass[12pt,oneside,a4paper,brazil]{report} \usepackage{epsfig} \usepackage{multirow} \usepackage{caption} \usepackage{longtable} \usepackage{xcolor} \usepackage{colortbl} \usepackage{pdflscape} \usepackage{enumitem} \usepackage{tabularx} \usepackage{pdfpages} \usepackage{algorithm} \usepackage{float} \usepackage{babel} \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} \usepackage{amsmath} \usepackage[noend]{algpseudocode} – user117680 Nov 1 '16 at 11:55
• You should add them in your post, and write a full minimal (non-)working example. But what is the problem exactly? – Bernard Nov 1 '16 at 12:00
• The problem is that the code is not being displayed properly. For example, the "Se |C2| > |C|" should be in a new line (it's the IF command, but in Portuguese" – user117680 Nov 1 '16 at 12:07
• your code generates errors ! Missing } inserted. <inserted text> } after an error it is not worth even looking at the generated pdf, your question should have asked about the error not shown the output. Also If I run it, I get a line break before If and it says If not Se. I will add a document to your question but please edit it to show the problem. – David Carlisle Nov 1 '16 at 12:31

After adding an missing closing bracket } in your code I can compile without error---and for me without missing line break!

\documentclass[12pt,oneside,a4paper,brazil]{report}

\usepackage{algorithm}
\usepackage{float}
\usepackage{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage[noend]{algpseudocode}
\newcommand\BB{BB}

\begin{document}
\begin{algorithm}
\caption{The \BB algorithm}
\begin{algorithmic}
\State \BB(G, Q, K)
\State $\text{C} \gets \text{Q}$
\If {$\text{K} \neq \emptyset$ }
\State $\text{v} \gets \text{a vertex in K}$
\State ${C_1 \gets BB(G, Q \cup \{v\}, U \cap \Gamma_G(v))}$
\If {$|C_1| > |C|$}
\State $C \gets C_1$
\EndIf
\State $C_2 \gets BB(G, Q, K - v)$
\If {$|C_2| > |C|$}
\State $C \gets C_2$
\EndIf
\EndIf
\Return $C$
\end{algorithmic}
\end{algorithm}

\end{document}
`

and its result: