我正在尝试在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}
在samcarter_is_at_toanswers.xyz的帮助下,我对LaTex的运行方式有了更多的了解。问题是由于某种原因,MiKTeX 2.9文件已不存在(或者至少不能通过LaTeX或手动找到)。
所以我用了answerd question来指导我重新安装MiKTeX。解决了这个问题。重新安装后,TeXmaker能够下载float package
和float.sty
,这是我需要解决的由algorithm package
引起的原始错误。
我几乎没有使用LaTeX / TeXmaker / MiKTeX的经验,而且我对计算机的了解也不是那么熟练。因此,请让我知道您是否对问题有更好的答案/解释/理解。我将编辑/删除我的答案。