我正在尝试编写一种算法,即在编译 latex 后,代码中的单独行应该是单独的行。我使用 \ 符号来实现这一点,但由于某种原因,它不起作用。我使用 overleaf 来工作和编译 latex。
包
\usepackage[utf8]{inputenc}
\usepackage{biblatex}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage[linesnumbered,ruled,vlined]{algorithm2e}
代码
\begin{algorithm}[H] \label{algo:2}
\SetAlgoLined
\DontPrintSemicolon
\KwData{goldGPU} \label{alg:alg2Dat1} \
\KwData{segmGPU} \
\KwData{numberToLookFor} \label{alg:alg2Dat3} \
boolGold = goldGPU[x,y,z]==numberToLookFor \label{alg:alg2A1} \
boolSegm = segmGPU[x,y,z]==numberToLookFor \
if(boolGold)\label{alg:alg2A2} \
addSumXYZGold() \
end if \
if(boolSegm) \
addSumXYZSegm() \
end if \
syncGrid()\label{alg:alg2A3} \
if(boolGold)\label{alg:alg2A4} \
getVariancesAndCovGold() \
end if \
if(boolSegm) \
getVariancesAndCovSegm() \
end if \
syncGrid() \
a = sqrt(varianceX) \label{alg:alg2A5} \
b = (covarianceXY)/a \
c = (covarianceXZ)/a \
e = sqrt(varianceY - b^2) \
d = (covarianceYZ -(c * b))/e \
f= (meanXgold -meanXsegm) /a \label{alg:alg2A6} \
g = ( meanYgold -meanYsegm) -b*f)/e\
h= ( meanZgold -meanZsegm ) -g*d-f* c)/sqrt(varianceZ - c^2 -d^2)\
result = sqrt(f^2+g^2+h^2)\
return result
\label{alg:a2}\
\caption{Calculating Mahalanobis distance}
\end{algorithm}
所以问题是如何分隔行,例如从 a=; b= ... 开头的行应该在新行中,而它们不是我做错了什么?