1

When I put an If block inside an algorithm doesn't show.

\documentclass[a4paper,english,12pt,oneside]{book}
%\documentclass[11pt,draft]{article}
%\usepackage{fullpage}
%\usepackage[top=1in, bottom=1in, left=1in, %right=1in]{geometry}
%\usepackage[margin=1in, paperwidth=8.5in, paperheight=11in]{geometry}
\usepackage[left=2cm, right=2cm, top=2.5cm, bottom=2.5cm]{geometry}
%\usepackage[left=20mm]{geometry}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{graphicx}
\usepackage{refstyle}
\usepackage{subcaption}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{enumerate}
\usepackage{epstopdf}
\usepackage{breqn}
\usepackage{mathtools}
%--------------------------------------------------------------------------------------------------
%\usepackage{a4wide}
\usepackage{amsfonts}
\usepackage{amstext}
\usepackage{amsthm}
\usepackage{newlfont}
\usepackage{graphics}
\usepackage{tabularx}
\usepackage{geometry}
\usepackage{lscape}
\usepackage{multirow}
\usepackage{epsfig}
%Alg Package ------------------------------------------------------------------------------------------
\usepackage{algorithm}
\usepackage{algcompatible}
\usepackage{algorithmicx}
\usepackage{algpseudocode}
\usepackage{pifont}

\begin{document}
1) first case:

\begin{algorithmic}[1]
\If{$quality\ge 9$}
\State $v'_{\theta} = - \|U\|'_{\theta} e_1$
\Else
\State $v'_{\theta} = + \|U\|'_{\theta} e_1$
\ENDIF
\EndIf
\end{algorithmic}

2) second case:

\begin{algorithm}
\caption{DER ($U,U'_{\theta}$)}
\label{CHalgorithm}
\begin{algorithmic}[1]
\Procedure{process}{}
\State $\|U\|'$
\IF {$U(1)\ge 0$}
    \State $v'_{\theta} = - \|U\|'_{\theta} e_1$
\ELSE
    \State $v'_{\theta} = + \|U\|'_{\theta} e_1$
\ENDIF
\State $\|v\|'_{\theta} = $
\State $u'_{\theta} = $
\State $(H_u)'_{\theta} = $  
\EndProcedure
\end{algorithmic}
\end{algorithm}

\end{document}
0

You load too many algorithm packages. I suggest to load only

\usepackage{algorithm}
\usepackage{algpseudocode}

algpseudocode loads algorithmicx anyway.

The problem that the if-then-else does not show is just that you chose the wrong keywords. For algpseudocode they are \If-\Else-\EndIf.

enter image description here

\documentclass{book}
\usepackage{algorithm}
%\usepackage{algcompatible}
%\usepackage{algorithmicx}
\usepackage{algpseudocode}

\begin{document}
1) first case:

\begin{algorithmic}[1]
\If{$quality\ge 9$}
\State $v'_{\theta} = - \|U\|'_{\theta} e_1$
\Else
\State $v'_{\theta} = + \|U\|'_{\theta} e_1$
\EndIf
\end{algorithmic}

2) second case:

\begin{algorithm}
\caption{DER ($U,U'_{\theta}$)}
\label{CHalgorithm}
\begin{algorithmic}[1]
\Procedure{process}{}
\State $\|U\|'$
\If {$U(1)\ge 0$}
    \State $v'_{\theta} = - \|U\|'_{\theta} e_1$
\Else
    \State $v'_{\theta} = + \|U\|'_{\theta} e_1$
\EndIf
\State $\|v\|'_{\theta} = $
\State $u'_{\theta} = $
\State $(H_u)'_{\theta} = $  
\EndProcedure
\end{algorithmic}
\end{algorithm}

\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.