latex怎么让eif的else向右缩进?

这里是latex的代码


\documentclass{article}

 \usepackage[ruled]{algorithm2e}                 %算法排版样式1
%\usepackage[ruled,vlined]{algorithm2e}          %算法排版样式2
%\usepackage[linesnumbered,boxed]{algorithm2e}   %算法排版样式3
 \usepackage{indentfirst}

%\textwidth 20 true cm% 正文宽
%\textheight 30 true cm% 正文高
%\headheight 14pt% 页眉高
%\headsep20pt% 页眉距离
%\footskip27pt% 页脚距离
%\marginparsep 19pt% 边注区距离
%\marginparwidth 100pt% 边注区宽



\begin{document}

\begin{minipage}{14cm}


%    ------------------------------Example - 1---------------------------------------------

        \begin{algorithm}[H]

            \caption{Coverage criterion algorithm for data plane topology test}
            \KwIn{host $H$ that $Dataplane(DP)$ is fetched from, switches $V$ that $DP$ belongs to, links $E$ that $DP$ belongs to,$TP_{set}$,$tp_{res}$  }
            \KwOut{Test\_path and Iperf test result }

            \textbf{def} vertex\_coverage(test\_road):\\
            \hspace*{0.6cm}\While{has (V or E)_{attribute=0}}{
                    \hspace*{0.6cm}test\_coverage\;
                    \hspace*{0.6cm}Slect a (V or E)\_{attribute=0} consist test\_path to test;\\
                    \hspace*{0.6cm}use iperf test path and print the test\_result;\\
                    \hspace*{0.6cm}
                    \eIf{$TP_{set}$\geq$tp_{res}$ }
                    {
                           \hspace*{0.6cm}output: test\_road is right\;
                           
                    }
                      {
                        \hspace*{0.6cm}{The output test\_path is wrong}\\
                        \hspace*{0.6cm}{fault location is performed at the end}
                    }
                }
                \end{algorithm}

%\makeatletter
%\newif\if@restonecol
%\makeatother
%\let\algorithm\relax
%\let\endalgorithm\relax
\end{minipage}

\end{document}

这里是输出的pdf文件,我想让被圈起来的部分向右缩进,请问应该如何修改代码?🙏

img

参考GPT和自己的思路:

您好!根据您的描述,可以使用\SetAlgoHangIndent{1.5em}命令来设置算法中的else语句的缩进。这里的1.5em可以根据需要进行调整。具体的修改代码如下所示:

\documentclass{article}

\usepackage[ruled]{algorithm2e} %算法排版样式1
%\usepackage[ruled,vlined]{algorithm2e} %算法排版样式2
%\usepackage[linesnumbered,boxed]{algorithm2e} %算法排版样式3
\usepackage{indentfirst}

\begin{document}

\begin{minipage}{14cm}

%----------------------------Example - 1---------------------------------------------
\begin{algorithm}[H]
    \caption{Coverage criterion algorithm for data plane topology test}
    \KwIn{host $H$ that $Dataplane(DP)$ is fetched from, switches $V$ that $DP$ belongs to, links $E$ that $DP$ belongs to,$TP_{set}$,$tp_{res}$  }
    \KwOut{Test\_path and Iperf test result }
    
    \SetAlgoHangIndent{1.5em} % 设置缩进大小
    
    \textbf{def} vertex\_coverage(test\_road):\\
    \hspace*{0.6cm}\While{has (V or E)\_{attribute=0}}{
        \hspace*{0.6cm}test\_coverage\;
        \hspace*{0.6cm}Slect a (V or E)\_{attribute=0} consist test\_path to test;\;
        \hspace*{0.6cm}use iperf test path and print the test\_result;\;
        \hspace*{0.6cm}
        \eIf{$TP_{set}\geq tp_{res}$}{
            \hspace*{0.6cm}output: test\_road is right\;
        }{
            \hspace*{0.6cm}The output test\_path is wrong\;
            \hspace*{0.6cm}fault location is performed at the end
        }
    }
\end{algorithm}

\end{minipage}

\end{document}

修改后的结果如下所示:

![img](https://img-blog.csdn.net/2018052822055653?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvSW5zdGFuY2VlTW9kZWw=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve