2

In my algorithm, I wrote input and output as follows.

    \begin{algorithm}[htb!]
    \caption{Data Preprocessing}
    \label{alg:data_preprocessing}
    \textbf{Input} input data \\
    \textbf{Output} Preprocessed output dataset
    \begin{algorithmic}[1]
    \STATE
    ...
    \RETURN $processed\_output$
    \end{algorithmic}
    \end{algorithm}

But I am facing a problem with the output as shown in the attached picture.

enter image description here

What is the cause of this problem and how can I solve it?

1

1 Answer 1

4

You can leave a blank line between your Input and Output statements, which sets the proper alignment:

enter image description here

\documentclass[twocolumn]{article}

\usepackage{algorithm}
\usepackage{algorithmic}

\begin{document}

\begin{algorithm}
  \caption{Data Preprocessing}
  \textbf{Input} input data \\
  \textbf{Output} Preprocessed output dataset
    
  \begin{algorithmic}[1]
    \STATE Something
    \STATE \ldots
    \RETURN Something else
  \end{algorithmic}
\end{algorithm}

\end{document}

However, a better approach is to use the functionality provided by algorithmic through \REQUIRE (for input) and \ENSURE (for output):

enter image description here

\documentclass[twocolumn]{article}

\usepackage{algorithm}
\usepackage{algorithmic}

\begin{document}

\begin{algorithm}
  \caption{Data Preprocessing}
  \begin{algorithmic}[1]
    \REQUIRE input date
    \ENSURE Preprocessed output dataset
    \STATE Something
    \STATE \ldots
    \RETURN Something else
  \end{algorithmic}
\end{algorithm}

\end{document}

You can adjust the formatting/style of the output produced by \REQUIRE and \ENSURE via a \renewcommand of their defaults:

\newcommand{\algorithmicrequire}{\textbf{Require:}}
\newcommand{\algorithmicensure}{\textbf{Ensure:}}

You must log in to answer this question.

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