算法:代码行重叠,最终水平线错位

算法:代码行重叠,最终水平线错位

我目前正在改编一篇文章以适应MDPI 模板我在使用算法包时遇到了一些问题。代码行重叠,最后一行代码出现在末尾水平线下方。这是我的主文件:

\documentclass[sensors,article,submit,moreauthors,pdftex,10pt,a4paper]{Definitions/mdpi}

\usepackage{conf-simple}


\firstpage{1} 


\makeatletter 
 \setcounter{page}{\@firstpage} 
 \makeatother \pubvolume{xx} 
\issuenum{1} \articlenumber{1}
 \pubyear{2018}
\copyrightyear{2018} 
\externaleditor{Academic Editor: name} 
\history{Received: date; Accepted: date; Published: date} 
\Title{Title} % Author Orchid ID: enter ID or remove command \newcommand{\orcidauthorA}{0000-0000-000-000X} % Add \orcidA{} behind the author's name %\newcommand{\orcidauthorB}{0000-0000-000-000X} % Add \orcidB{} behind the author's name

% Authors, for the paper (add full first names) \Author{Firstname Lastname $^{1,\dagger,\ddagger}$\orcidA{}, Firstname Lastname $^{1,\ddagger}$ and Firstname Lastname $^{2,}$*}

% Authors, for metadata in PDF \AuthorNames{Firstname Lastname, Firstname Lastname and Firstname Lastname}

% Affiliations / Addresses (Add [1] after \address if there is only one affiliation.) \address{%
    $^{1}$ \quad Affiliation 1; [email protected]\\
    $^{2}$ \quad Affiliation 2; [email protected]} \corres{Correspondence: [email protected]; Tel.: +x-xxx-xxx-xxxx} \firstnote{Current address: Affiliation 3}  \secondnote{These authors contributed equally to this work.} \begin{document} \section{Hello}

\begin{algorithm}[H]
    \caption{: do something \label{alg:1}}
    \begin{algorithmic}[1] % The number tells where the line numbering should start
    \Procedure {Do}{something $n$}
         \If {connected}
           \State send 
         \Else 
           \State store 
         \EndIf
     \EndProcedure 
    \end{algorithmic} \end{algorithm}


\end{document}

我的 conf-simple.sty 文件:

\ProvidesPackage{conf-simple}

\usepackage{algorithm}
\usepackage[noend]{algpseudocode} 
\renewcommand{\ALG@beginalgorithmic}{\scriptsize}

这是我想要的输出: 在此处输入图片描述

如果我将 documentclass 更改为 \documentclass{article},则会生成。但是,使用 mpdi 模板得到的结果是: 在此处输入图片描述

我已经发现这个问题我已经尝试遵循建议的解决方案。但是,添加 \setlength\baselineskip{20pt} 对我的输出没有影响。只有当我注释将字体大小设置为 scriptsize 的配置行时,它才会起作用。然后,它解决了重叠线问题,但没有解决最终水平线的问题。这是输出: 在此处输入图片描述

不过,我宁愿保持脚本大小。

有什么方法可以获得我想要的输出吗?

答案1

我还不知道这种不兼容性从何而来。但我有一个解决方案。使用spacing环境来增加间距:

\begin{algorithm}[H]
    \caption{: do something \label{alg:1}}
    \begin{spacing}{2} %% you can adjust the amount of spacing here
    \begin{algorithmic}[1]
    \Procedure {Do}{something $n$}
         \If {connected}
           \State send 
         \Else 
           \State store 
         \EndIf
     \EndProcedure 
    \end{algorithmic} 
    \end{spacing} %% end of the spacing environment
\end{algorithm}

相关内容