There is an incompatibility between the algorithm2e
/algorithmic
packages and revtex4-1
; one possibility is to use algcompatible
instead of algorithmic
(the syntax of the commands is the same and this solves the indentation problem) and to use the newfloat
package to define a new algorithm
float. Here's an example illustrating this approach (I used a table
and a figure
environments to show how the newly defined float behaves consistently with the class):
\documentclass{revtex4-1}
\usepackage{algcompatible}
\usepackage{newfloat}
\DeclareFloatingEnvironment[
fileext=loa,
listname=List of Algorithms,
name=ALGORITHM,
placement=tbhp,
]{algorithm}
\begin{document}
\begin{figure}
\rule{2cm}{2cm}
\caption{A test caption for a figure}
\end{figure}
\begin{table}
\rule{2cm}{2cm}
\caption{A test caption for a table}
\end{table}
\begin{algorithm}
\begin{algorithmic}
\FOR{every thing you}
\FOR{every step you}
\STATE{compute something}
\ENDFOR
\ENDFOR
\end{algorithmic}
\caption{Calculate something}
\end{algorithm}
\end{document}
If one wants to keep the ruled
style of the algorithm
environmet, as defined in algorithm2e
, some additional work has to be done; in this case, the caption
package could be used (providing one makes the necessary adjustments to recover the formatting defined in revtex4-1
); here's such possibility with a little example:
\documentclass{revtex4-1}
\usepackage{newfloat,algcompatible}
\usepackage[size=small]{caption}
\usepackage{etoolbox}
\AtBeginEnvironment{algorithm}{\noindent\hrulefill\par\nobreak\vskip-5pt}
\usepackage{newfloat}
\DeclareFloatingEnvironment[
fileext=loa,
listname=List of Algorithms,
name=ALGORITHM,
placement=tbhp,
]{algorithm}
\DeclareCaptionFormat{algorithms}{\vskip-15pt\hrulefill\par#1#2#3\vskip-6pt\hrulefill}
\captionsetup[algorithm]{singlelinecheck=off,format=algorithms}
\begin{document}
\begin{figure}
\rule{2cm}{2cm}
\caption{A test caption for a figure}
\end{figure}
\begin{algorithm}
\begin{algorithmic}
\FOR{every thing you}
\FOR{every step you}
\STATE{compute something}
\ENDFOR
\ENDFOR
\end{algorithmic}
\caption{Calculate something}
\end{algorithm}
\end{document}
If, for some reason, the newfloat
packageis not available, one can use the trivfloat
instead:
\documentclass{revtex4-1}
\usepackage{algcompatible}
\usepackage[floatrow]{trivfloat}
\trivfloat{algorithm}
\renewcommand\algorithmname{ALGORITHM}
\begin{document}
\begin{figure}
\rule{2cm}{2cm}
\caption{A test caption for a figure}
\end{figure}
\begin{table}
\rule{2cm}{2cm}
\caption{A test caption for a table}
\end{table}
\begin{algorithm}
\begin{algorithmic}
\FOR{every thing you}
\FOR{every step you}
\STATE{compute something}
\ENDFOR
\ENDFOR
\end{algorithmic}
\caption{Calculate something}
\end{algorithm}
\end{document}
I was trying to have the packages updated while running TexMaker. This process always failed if I did not start TexMaker as an Administrator.
The issue is resolved if Texmaker is run as Administrator. I guess this is something both Texmaker and MikTex should look into resolving.
Best Answer
You probably have not installed the full TeX Live but only a decent selection of it. To get the package you are after you can either
algorithm2e
(the same package also containsalgorithmicx
).To install the latter you can issue the following in a terminal: