To use the command \captionsetup
you must have loaded the caption
package...
Anyway, this can be done without it.
First of all, the spacing between the caption and the rest of the text is null because you are preventing the algorithm
to float using H
as a position specifier. Use h
instead, which means "place it here" but keeps the algorithm
a floating object (the same as h
for figure
s and table
s).
Then you can adjust the spacing between the body of the algorithm
and its caption through the command \SetAlCapSkip
.
In other words, substituting the line
\begin{algorithm}[H]
with
\begin{algorithm}[h]
and inserting
\SetAlCapSkip{1em}
in the preamble (adjust 1em
to your needs) should be what you want.
Complete MWE
\documentclass[a4paper]{article}
\usepackage{blindtext}
\usepackage[linesnumbered,boxed]{algorithm2e}
\SetAlCapSkip{1em}
\SetKwInput{KwInput}{Input}
\SetKwInput{KwOutput}{Output}
\begin{document}
\begin{algorithm}[h]
\SetAlgoLined
\KwInput{Parameters...}
\KwOutput{$\emptyset$}
\If{Condition}
{
Do something \;
}
\caption{Algoritm test...}
\end{algorithm}
\blindtext{}
\begin{figure}[!h]
\caption{Figure test...}
\end{figure}
\blindtext{}
\end{document}
Output
You can create a do-while construct using the same technique that a repeat-until construct is generated. They both fall under what algorithm2e
calls "Repeat macros":
\SetKwRepeat{Do}{do}{while}
The above now allows you to use
\Do{<end condition>}{<stuff>}
Here is a minimal example showing its use/output:
\documentclass{article}
\usepackage[linesnumbered, ruled]{algorithm2e}
\SetKwRepeat{Do}{do}{while}%
\begin{document}
\begin{algorithm}[H]
\KwData{this text}
\KwResult{how to write algorithm with \LaTeX2e }
initialization\;
\While{not at end of this document}{
read current\;
\Repeat{this end condition}{
do these things\;
}
\eIf{understand}{
go to next section\;
current section becomes this one\;
}{
go back to the beginning of current section\;
}
\Do{this end condition}{
do these things\;
}
}
\caption{How to write algorithms}
\end{algorithm}
\end{document}
Best Answer
You can define custom keywords using the
\SetKw
command, as described in Section 11 of the manual. MWE:Result:
Note: for future questions, please always provide an example of code that you have tried, so it is easier to provide a solution.