algorithm2e - override defaults
You have to adjust the settings manually:
\documentclass{article}
\usepackage[ruled,vlined,linesnumbered,noresetcount]{algorithm2e}
\makeatletter
\newcommand{\AlgoResetCount}{\renewcommand{\@ResetCounterIfNeeded}{\setcounter{AlgoLine}{0}}}
\newcommand{\AlgoNoResetCount}{\renewcommand{\@ResetCounterIfNeeded}{}}
\newcounter{AlgoSavedLineCount}
\newcommand{\AlgoSaveLineCount}{\setcounter{AlgoSavedLineCount}{\value{AlgoLine}}}
\newcommand{\AlgoRestoreLineCount}{\setcounter{AlgoLine}{\value{AlgoSavedLineCount}}}
\makeatother
\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\;
\eIf{understand}{
go to next section\;
current section becomes this one\;
}{
go back to the beginning of current section\;
}
}
\caption{How to write algorithms}
\end{algorithm}
\RestyleAlgo{boxed}% Change from the 'ruled' style to 'boxed'
\SetAlgoNoLine% Removes 'vlined' option (somewhat opposite of \SetAlgoVlined)
\LinesNumberedHidden% Removes 'linesnumbered' option (opposite of \LinesNumbered)
\AlgoSaveLineCount% Stores the algorithm line number (similar to 'resetcount' in the package load option)
\begin{algorithm}[H]
\KwData{this text}
\KwResult{how to write algorithm with \LaTeX2e }
initialization\;
\While{not at end of this document}{
read current\;
\eIf{understand}{
go to next section\;
current section becomes this one\;
}{
go back to the beginning of current section\;
}
}
\caption{How to write algorithms}
\end{algorithm}
\RestyleAlgo{ruled}% Change from the 'boxed' style to 'ruled'
\SetAlgoVlined% Similar to 'vlined' in the package load option
\LinesNumbered% Similar to 'linesnumbered' in the package load option
\AlgoRestoreLineCount% Restores the algorithm line number (similar to 'noresetcount' in the package load option)
\begin{algorithm}[H]
\KwData{this text}
\KwResult{how to write algorithm with \LaTeX2e }
initialization\;
\While{not at end of this document}{
read current\;
\eIf{understand}{
go to next section\;
current section becomes this one\;
}{
go back to the beginning of current section\;
}
}
\caption{How to write algorithms}
\end{algorithm}
\end{document}
Not much manual adjustment is needed! You only add
\RestyleAlgo{options}
right before the algorithm definition you want to be overridden.
Note that options can be one of the followings: boxed
, boxruled
, ruled
and algoruled
.
Ex:
After defining \usepachage[]{algorithm2e}
in preamble:
\RestyleAlgo{ruled}
\begin{algorithm}
....
\end{algorithm}
That's it!