首页 > 解决方案 > Latex 算法环境 float.sty 未找到

问题描述

我正在尝试在 Latex 中生成算法,但不断收到相同的错误:! LaTeX Error: File 'float.sty' not found.. 即使我在新文档中重新创建示例。

当我使用algorithm应该允许我创建算法环境的包时会出现问题。日志文件表明 LaTeX 找不到float.sty.

只需简单地添加\usepackage{float}到序言中,就可以找到一个简单的解决方案。但是添加包会导致上线出错\usepackage{algorithm}

这是示例代码:

\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}

标签: algorithmlatexenvironmentpdflatex

解决方案


在 samcarter_is_at_toanswers.xyz 提供的帮助下,我对 LaTeX 的运作方式有了更多的了解。问题是 MiKTeX 2.9 文件由于某种原因不再存在(或者至少无法通过 LaTeX 或手动定位)。

所以我使用这个已回答的问题来指导我重新安装 MiKTeX。这解决了问题。float package重新安装后,TeXmaker 能够下载float.sty我需要解决由algorithm package.

我对 LaTeX/TeXmaker/MiKTeX 几乎没有经验,而且我对计算机的技术也不是那么好。因此,如果您对问题有更好的答案/解释/理解,请告诉我。我将编辑/删除我的答案。


推荐阅读