0

During writing an algorithm using Latex syntax I encountered indentation problem that new line below line 2 didn't align line 2?

enter image description here

We can see that the 'conainer ct' exceed the scope of for

Here is the latex code:

\documentclass[conference]{IEEEtran}
\usepackage{algorithm}
\usepackage{algpseudocode}
\usepackage{amsmath}
\begin{document}
\renewcommand{\algorithmicrequire}{\textbf{Input:}}  % Use Input in the format of Algorithm
\renewcommand{\algorithmicensure}{\textbf{Output:}} % Use Output in the format of Algorithm

\begin{algorithm}[h]
    \caption{CC-WFDLBP}
    \label{alg:wfd}
    \begin{algorithmic}[1]
        \Require
        $CC$: Container Cluster to be placed,
        $H$: Set of Hosts
        \Ensure
        Placement Strategy $P$
        \For{Container $ct$ $\in$ $CC$}
            \State compute the dominant resource $dr$ by the current container $ct$
        \State compute Polak-Ribiere parameter $\beta_k=\frac{g_k^{T}(g_k-g_{k-1})}{\parallel g_{k-1} \parallel^{2}}$;
        \State compute the conjugate directions $d_k=-g_k+\beta_k d_{k-1}$;
        \State compute the step size $\alpha_k=s/\parallel d_k \parallel_{2}$;
        \EndFor
    \end{algorithmic}
\end{algorithm}
\end{document}

1 Answer 1

1

algpseudocodex package can solve your problem.

In addition, I have revised some styles in order to be more in line with IEEE style requirements. And I gave two styles.

\documentclass[conference]{IEEEtran}
\usepackage{algorithm}
\floatplacement{algorithm}{tbp}
\makeatletter
\newcommand{\algorithmname}{\ALG@name}
\renewcommand{\floatc@ruled}[2]{{\@fs@cfont #1:} #2\par}
\makeatother
\usepackage[noEnd=false]{algpseudocodex}
\tikzset{algpxIndentLine/.style={draw=black}}
\algrenewcommand{\alglinenumber}[1]{\bfseries\footnotesize #1}
\algrenewcommand{\textproc}{}
\begin{document}
\algrenewcommand{\algorithmicrequire}{\textbf{Input:}}  % Use Input in the format of Algorithm
\algrenewcommand{\algorithmicensure}{\textbf{Output:}} % Use Output in the format of Algorithm

\begin{algorithm}[h]
    \caption{CC-WFDLBP}
    \label{alg:wfd}
    \begin{algorithmic}[1]
        \Require
        $CC$: Container Cluster to be placed,
        $H$: Set of Hosts
        \Ensure
        Placement Strategy $P$
        \For{Container $ct$ $\in$ $CC$}
            \State compute the dominant resource $dr$ by the current container $ct$
        \State compute Polak-Ribiere parameter $\beta_k=\frac{g_k^{T}(g_k-g_{k-1})}{\parallel g_{k-1} \parallel^{2}}$;
        \State compute the conjugate directions $d_k=-g_k+\beta_k d_{k-1}$;
        \State compute the step size $\alpha_k=s/\parallel d_k \parallel_{2}$;
        \EndFor
    \end{algorithmic}
\end{algorithm}
\end{document}

enter image description here

\documentclass[conference]{IEEEtran}
\usepackage{algorithm}
\floatplacement{algorithm}{tbp}
\makeatletter
\newcommand{\algorithmname}{\ALG@name}
\renewcommand{\floatc@ruled}[2]{{\@fs@cfont #1:} #2\par}
\makeatother
\usepackage{algpseudocodex}
\tikzset{algpxIndentLine/.style={draw=black}}
\algrenewcommand{\alglinenumber}[1]{\bfseries\footnotesize #1}
\algrenewcommand{\textproc}{}
\begin{document}
\algrenewcommand{\algorithmicrequire}{\textbf{Input:}}  % Use Input in the format of Algorithm
\algrenewcommand{\algorithmicensure}{\textbf{Output:}} % Use Output in the format of Algorithm

\begin{algorithm}[h]
    \caption{CC-WFDLBP}
    \label{alg:wfd}
    \begin{algorithmic}[1]
        \Require
        $CC$: Container Cluster to be placed,
        $H$: Set of Hosts
        \Ensure
        Placement Strategy $P$
        \For{Container $ct$ $\in$ $CC$}
            \State compute the dominant resource $dr$ by the current container $ct$
        \State compute Polak-Ribiere parameter $\beta_k=\frac{g_k^{T}(g_k-g_{k-1})}{\parallel g_{k-1} \parallel^{2}}$;
        \State compute the conjugate directions $d_k=-g_k+\beta_k d_{k-1}$;
        \State compute the step size $\alpha_k=s/\parallel d_k \parallel_{2}$;
        \EndFor
    \end{algorithmic}
\end{algorithm}
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .