2

I need to add an indent in front of 'climate' and 'each region' so that the overflowing lines aren't confused for a new line of pseudocode. enter image description here I have tried everything including this (the algorithm2e package wasn't working for me for some reason) and I've tried the usual \ to add a space, $\thinmuskip$, \indent to add an indent, and other things that didn't work. My latex code is below

\documentclass{article}    
\usepackage[ruled,vlined]{algorithm2e}
\usepackage{algorithm}
\begin{document}

\begin{algorithm}[H] \SetAlgoLined initialisation: choose initial emission control rates $\boldsymbol{\mu^k}=[\mu^k(1) \ ... \ \mu^k(Tmax)]$ for each region $k \in 1,...,12$; store initial $\boldsymbol{\mu} ^k$ in vector $CR$;

\For{\textup{each region $i \in 1,...,12$}}{{\nosemic find $\boldsymbol{\mu^i}$ that maximises $\sum_{t=1}^{Tmax} U[c^{i}(t), L^{i}(t)]R(t)$ subject to economic and ; climate equations, with all other $\boldsymbol{\mu} ^k$ fixed from $CR$;

replace the old value of $\boldsymbol{\mu^i}$ in $CR$ with the new optimal $\boldsymbol{\mu^i}$; } } \While{\textup{|$\boldsymbol{\mu^i}-\boldsymbol{\mu^j}$|>threshold for some regions $i,j$}}{ {repeat \textbf{for} loop; } } \caption{Noncooperative Equilibrium for RICE} \end{algorithm}

\end{document}

Marijn
  • 37,699

2 Answers2

4

I still have trouble compiling your example. But I guess there is quick hack for your question: Just insert something like \phantom{for} in front of the word climate:

\documentclass{article}
\usepackage[ruled,vlined]{algorithm2e}
\usepackage{algorithm}
\begin{document}

\begin{algorithm}[H] \SetAlgoLined initialisation: choose initial emission control rates $\boldsymbol{\mu^k}=[\mu^k(1) \ ... \ \mu^k(Tmax)]$ for each region $k \in 1,...,12$; store initial $\boldsymbol{\mu} ^k$ in vector $CR$;

\For{\textup{each region $i \in 1,...,12$}}{{\nosemic find $\boldsymbol{\mu^i}$ that maximises $\sum_{t=1}^{Tmax} U[c^{i}(t), L^{i}(t)]R(t)$ subject to economic and ; \phantom{for} climate equations, with all other $\boldsymbol{\mu} ^k$ fixed from $CR$;

replace the old value of $\boldsymbol{\mu^i}$ in $CR$ with the new optimal $\boldsymbol{\mu^i}$; } } \While{\textup{|$\boldsymbol{\mu^i}-\boldsymbol{\mu^j}$|>threshold for some regions $i,j$}}{ {repeat \textbf{for} loop; } } \caption{Noncooperative Equilibrium for RICE} \end{algorithm}

\end{document}

enter image description here

citsahcots
  • 7,992
2

You can do \SetAlgoHangIndent{1.5em} (or whatever length you deem good). I also suggest other changes to avoid clumsy input and for consistency.

Note that you should not load algorithm2e and algorithm together.

\documentclass{article}    
\usepackage[ruled,vlined]{algorithm2e}
\usepackage{amsmath}

\begin{document}

\begin{algorithm} \SetAlgoLined \SetAlgoHangIndent{1.5em} \SetArgSty{textnormal} \textbf{initialisation:} choose initial emission control rates $\boldsymbol{\mu}^k=[\mu^k(1) \dots \mu^k(T_{\mathrm{max}})]$ for each region $k \in 1,\dots,12$; store initial $\boldsymbol{\mu}^k$ in vector $CR$;

\For{each region $i \in 1,\dots,12$}{% find $\boldsymbol{\mu}^i$ that maximises $\sum_{t=1}^{T_{\mathrm{max}}} U[c^{i}(t), L^{i}(t)]R(t)$ subject to economic and climate equations, with all other $\boldsymbol{\mu}^k$ fixed from $CR$;

replace the old value of $\boldsymbol{\mu^i}$ in $CR$ with the new optimal $\boldsymbol{\mu}^i$; }

\While{$|\boldsymbol{\mu}^i-\boldsymbol{\mu}^j|> \text{threshold}$ for some regions $i,j$}{% {repeat \textbf{for} loop;} } \caption{Noncooperative Equilibrium for RICE} \end{algorithm}

\end{document}

enter image description here

egreg
  • 1,121,712