2

When I write a pseudo code using algorithm and algorithmic.

Output statement overflow a line like below.

\begin{algorithm}[!h]
\textbf{Input:} The set of public $parameters$\\
\textbf{Output:} Public key $pk = ({Seed}_{a}\parallel\mathbf{b})$, Private Key $sk = (\mathbf{s})$
\begin{algorithmic}[1]
    \STATE ${Seed}_{a} \xleftarrow{\$} {\{0, 1\}}^{256}$
    \STATE $\mathbf{a} \gets$ \texttt{SHAKE}256$({Seed}_{a}, n/8)$
    \STATE $\mathbf{s} \xleftarrow{\$} {HWT}_{n}({h}_{s})$
    \STATE $\mathbf{e} \xleftarrow{\$} {\psi}_{cb}^{n}$
    \STATE $\mathbf{b} \gets -\mathbf{a} \ast \mathbf{s} + \mathbf{e}$
    \STATE $pk \gets {Seed}_{a} \parallel \mathbf{b}$
    \STATE $sk \gets \mathbf{s}$
    \RETURN $pk, sk$
\end{algorithmic}
\caption{IND-CPA.KeyGen}
\label{Alg:IND-CPA.KeyGen}
\end{algorithm}

enter image description here

How to make this statement as one line?

  • 1
    Please make your code compilable by adding the documentclass as well as the relevant packages. – leandriis Sep 9 '19 at 11:30
  • 1
    @OP: The text is just too long to fit in one line. Either remove some text, or reduce the font size for the algorithm. – Saswat Padhi Sep 9 '19 at 12:53
  • Reduce the text size in the Output part of the algorithm environment. You can try the below mentioned snippet : \textbf{Output:} \footnotesize{Public key $pk = ({Seed}_{a}\parallel\mathbf{b})$, Private Key $sk = (\mathbf{s})$} – Mishra S Sep 9 '19 at 13:46
2

Well, you did not give us an compilable TeX code (that means start with \documentclass and end the code with \end{document}) so I have to guess a little bit. I hope I guessed right. Please next time add an compilable MWE, then we do not have to guess what you are doing ...

Instead of your used text before \begin{algorithmic} you can use the two commands \REQUIRE and \ENSURE like:

\REQUIRE The set of public $parameters$
\ENSURE  Public key $pk=({Seed}_{a}\parallel\mathbf{b})$, Private Key $sk=(\mathbf{s})$

To get your wished printed text "Input" and "Output" use in the preamble the commands

\renewcommand{\algorithmicrequire}{\textbf{Input:}} % <=================
\renewcommand{\algorithmicensure}{\textbf{Output:}} % <=================

Then you get the "Output" information printed in one line.

Please see the following complete and compilable MWE

\documentclass{article}

\usepackage{algorithm}
\usepackage{algorithmic}

\renewcommand{\algorithmicrequire}{\textbf{Input:}} % <=================
\renewcommand{\algorithmicensure}{\textbf{Output:}} % <=================

\usepackage{amsmath}


\begin{document}
\begin{algorithm}[!h]
\begin{algorithmic}[1]
\REQUIRE The set of public $parameters$
\ENSURE  Public key $pk=({Seed}_{a}\parallel\mathbf{b})$, Private Key $sk=(\mathbf{s})$
    \STATE ${Seed}_{a} \xleftarrow{\$} {\{0, 1\}}^{256}$
    \STATE $\mathbf{a} \gets$ \texttt{SHAKE}256$({Seed}_{a}, n/8)$
    \STATE $\mathbf{s} \xleftarrow{\$} {HWT}_{n}({h}_{s})$
    \STATE $\mathbf{e} \xleftarrow{\$} {\psi}_{cb}^{n}$
    \STATE $\mathbf{b} \gets -\mathbf{a} \ast \mathbf{s} + \mathbf{e}$
    \STATE $pk \gets {Seed}_{a} \parallel \mathbf{b}$
    \STATE $sk \gets \mathbf{s}$
    \RETURN $pk, sk$
\end{algorithmic}
\caption{IND-CPA.KeyGen}
\label{Alg:IND-CPA.KeyGen}
\end{algorithm}
\end{document}

and its result:

resulting algorithm

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.