Latex algorithm environment float.sty not found

Viewed 5862

I am trying to produce a algorithm in Latex but keep getting the same error: ! LaTeX Error: File 'float.sty' not found.. Even if i recreate examples in new documents.

The problem occurs when I use the package algorithm which should allow me to create a algorithm environment. The log file indicates that LaTeX couldn't find the float.sty.

A simple solution would been found by just simply adding \usepackage{float} to the preamble. But adding the package leads to an error on the line \usepackage{algorithm}.

Here is the example code:

\documentclass{article}


\usepackage{algpseudocode,algorithm,algorithmicx}
\newcommand*\DNA{\textsc{dna}}

\newcommand*\Let[2]{\State #1 $\gets$ #2}
\algrenewcommand\algorithmicrequire{\textbf{Precondition:}}
\algrenewcommand\algorithmicensure{\textbf{Postcondition:}}

\begin{document}

\begin{algorithm}
  \caption{Counting mismatches between two packed \DNA{} strings
    \label{alg:packed-dna-hamming}}
  \begin{algorithmic}[1]
    \Require{$x$ and $y$ are packed \DNA{} strings of equal length $n$}
    \Statex
    \Function{Distance}{$x, y$}
      \Let{$z$}{$x \oplus y$} \Comment{$\oplus$: bitwise exclusive-or}
      \Let{$\delta$}{$0$}
      \For{$i \gets 1 \textrm{ to } n$}
        \If{$z_i \neq 0$}
          \Let{$\delta$}{$\delta + 1$}
        \EndIf
      \EndFor
      \State \Return{$\delta$}
    \EndFunction
  \end{algorithmic}
\end{algorithm}
1 Answers

With the help samcarter_is_at_toanswers.xyz provided, I obtained a bit more understanding in how LaTeX operates. The problem was that the MiKTeX 2.9 file for some reason didn't exist anymore (or at least couldn't be located by LaTeX or manually).

So I used this answered question on to guide me to reinstall MiKTeX. This resolved the problem. After the reinstall TeXmaker was able to download the float package with the float.sty which I needed to resolve original error caused by the algorithm package.

I've little to no experience with LaTeX/TeXmaker/MiKTeX and I'am not that technical with computers. So please let me know if you have a better answer/explanation/understanding of the problem. I will edit/remove my answer.

Related