I am trying to write the algorithm in LaTeX File but it not able to indent properly.

In below url of an image enter image description here

Here the While Loop is not getting an indented, same way for if-else. Any help will be highly appreciated.

\lstset{basicstyle=\ttfamily, breaklines}

\subsection*{Figures and Tables}
\KwResult{Write here the result }
 \While{While condition}{
 \caption{How to write algorithms}

The document class of wlpeerj is as follows

\ProvidesClass{wlpeerj}[18/08/2016, v1.2]
\RequirePackage{times}      % Loads the Times-Roman Fonts
\RequirePackage{mathptmx}   % Loads the Times-Roman Math Fonts
\RequirePackage{lineno}     % For numbering the lines if lineno option is given




% writeLaTeX logo
% headers and footers
\RequirePackage{fancyhdr}  % custom headers/footers
\RequirePackage{lastpage}  % Number of pages in the document
\pagestyle{fancy}          % Enables the custom headers/footers
% Headers
% Footers
\renewcommand{\headrulewidth}{0pt}% % No header rule
\renewcommand{\footrulewidth}{0pt}% % No footer rule

% section/subsection/paragraph set-up
\titlespacing*{\section}{0pc}{3ex \@plus4pt \@minus3pt}{5pt}
\titlespacing*{\subsection}{0pc}{2.5ex \@plus3pt \@minus2pt}{0pt}
\titlespacing*{\subsubsection}{0pc}{2ex \@plus2.5pt \@minus1.5pt}{0pt}
\titlespacing*{\paragraph}{0pc}{1.5ex \@plus2pt \@minus1pt}{10pt}

% tableofcontents set-up
  {\ \titlerule*[.5pc]{.}\ \thecontentspage}
  [\ \textbullet\ ]  
%\setlist{nolistsep} % Uncomment to remove spacing between items in lists (enumerate, itemize)

% Remove brackets from numbering in List of References

% article meta data
%% LLT 18 Aug 2016: no more!
% \newcommand{\keywords}[1]{\def\@keywords{#1}}
%% LLT 18 Aug 2016: but need corresponding author
  Corresponding author:\par #2$^{#1}$\par
  Email address: #3\par}

\typeout{^^J^^J PLEASE DO NOT USE ANY \string\begin\space \string\end^^J
\gdef\theabstract{\vskip12pt BADLY FORMED ABSTRACT: PLEASE DO
NOT USE {\tt\string\begin...\string\end} COMMANDS WITHIN
THE ABSTRACT\vskip12pt}\let\go\relax\fi

% custom title page 
{\raggedright\sffamily\bfseries\fontsize{20}{25}\selectfont \@title\par}%
{\raggedright\sffamily\fontsize{12}{16}\selectfont  \@author\par}
% LLT 18 Aug 2016: needs corresponding author now
%% LLT 18 Aug 2016: no more keywords
% \vskip18pt%
% \noindent
% \parbox{\dimexpr\linewidth-2\fboxsep\relax}{%
% \if@peerjlineno\internallinenumbers\fi%
% {\color{color1}\keywordname\hspace*{1em}} \@keywords%
% }%
\setlength{\columnsep}{0.55cm} % Distance between the two columns of text
\setlength{\fboxrule}{0.75pt} % Width of the border around the abstract

\definecolor{color1}{RGB}{0,0,0} % Color of section headings
\definecolor{color2}{RGB}{250,232,207} % Color of the box behind the abstract
\newcommand{\keywordname}{Keywords:} % Defines the keywords heading name


\setlength\tocsep{1.5pc} % Sets the indentation of the sections in the table of contents
\setcounter{tocdepth}{3} % Show only three levels in the table of contents section: sections, subsections and subsubsections

\usepackage{lipsum} % Required to insert dummy text

The corresponding overleaf file is added below Overleaf File

  • 1
    Welcome to TEX.SE! Please post your code here. External links are discouraged because your question will become meaningless when the link disappears (next week, or next year, or... ).
    – campa
    Commented Feb 17, 2021 at 8:08
  • @campa Thank you for the suggestion. I had added the script here. Commented Feb 17, 2021 at 9:07
  • Since the template was written for Overleaf, you should contact their user support
    – DG'
    Commented Feb 17, 2021 at 9:38

1 Answer 1


Apparently whoever wrote that class never tested it thoroughly.

The error is that the class calls a few \RequirePackage before loading the base article class. Now, while there are certain situations where a package must be loaded before the class (like e.g. fix-cm) this is neither a general rule nor a universally good idea.

Specifically, the class contains

% ... other stuff ...

The package algorithm2e sets up the indentation in algorithms by means of its macro \SetInd, which is called immediately as


The trouble is that doing this before loading the article class means that the current font is \nullfont, and the em length unit is zero.

A quick workaround it to add \SetInd{0.5em}{1em} after \documentclass


but the class's author(s) should really improve the code.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .