伪代码中带有分数的更大行

伪代码中带有分数的更大行

我有上一个问题如何在 latex 中编写伪代码。我想在伪代码中使用分数,但带有分数的行有点小。有人知道如何让带有分数的行稍微大一点吗?

\usepackage{algpseudocode,amsmath}

\newcommand{\var}{\texttt}
\newcommand{\assign}{\leftarrow}
\newcommand{\multilinestate}[1]{%
\parbox[t]{\linewidth}{\raggedright\hangindent=\algorithmicindent\hangafter=1
\strut#1\strut}}

\begin{algorithmic}
\State \multilinestate{$\var{maxWeight} \assign{}$\var{e.weight} where~\var{e} has maximum weight of all elements}
\State \multilinestate{$\var{minWeight} \assign{}$\var{e.weight} where~\var{e} has minimum weight of all elements}
\State $\var{maxDraw} \assign{}$maximum size in visualization
\State $\var{minDraw} \assign{}$minimum size in visualization\\
\Function {CountDrawSize}{\var{elementWeight}}
\If{$\var{maxWeight} = \var{minWeight}$}
\State\Return $\dfrac{(\var{maxWeight} + \var{minWeight})}{2}$
\Else
\State\Return $\var{minDraw} + \dfrac{(\var{elementWeight} - \var{minWeight})(\var{maxDraw} - \var{minDraw})}{(\var{maxWeight} - \var{minWeight})}$
\EndIf
\EndFunction\\
\end{algorithmic}

在此处输入图片描述

答案1

(局部)增加\lineskip参数:

\documentclass{article}
\usepackage{algpseudocode,amsmath}

\newcommand{\var}{\texttt}
\newcommand{\assign}{\leftarrow}
\newcommand{\multilinestate}[1]{%
  \parbox[t]{\linewidth}{\raggedright\hangindent=\algorithmicindent\hangafter=1
  \strut#1\strut}}

\begin{document}

\begin{algorithmic}
\setlength{\lineskip}{3pt}
\State \multilinestate{$\var{maxWeight} \assign\var{e.weight}$ where~\var{e} has maximum weight of all elements}
\State \multilinestate{$\var{minWeight} \assign\var{e.weight}$ where~\var{e} has minimum weight of all elements}
\State $\var{maxDraw} \assign{}$maximum size in visualization
\State $\var{minDraw} \assign{}$minimum size in visualization\\
\Function {CountDrawSize}{\var{elementWeight}}
\If{$\var{maxWeight} = \var{minWeight}$}
\State\Return $\dfrac{(\var{maxWeight} + \var{minWeight})}{2}$
\Else
\State\Return $\var{minDraw} + \dfrac{(\var{elementWeight} - \var{minWeight})(\var{maxDraw} - \var{minDraw})}{(\var{maxWeight} - \var{minWeight})}$
\EndIf
\EndFunction
\end{algorithmic}

\end{document}

在此处输入图片描述

相关内容