Formatting pseudo-code Algorithm
I need to write the algorithm as formatted in the word. I need to insert initiate statement without taking any numbers, format symbols bold to indicate matrix, change the comments font and change algorithm font size only in the templet. this is the latex code.

begin{algorithm}
label{alg1}
DontPrintSemicolon
SetAlgoLined
SetKwInOut{Input}{Input}
SetKwInOut{Output}{Output}
Input{$e^n,e_{thr},snr_{thr},T_{tx},S_{id},l_x^n,l_y^n,l_z^n$}
Output{Optimized Routing Path for sensor node($S^*$)}
%Intiate{$h=1,RC{:,0}=0,fn=id^1$}
tcp*{$fn$ are the forwarding rely nodes for hop ($h$), $id^1$ is the ID of
source node, $RC$ is the total route cost.}
While{ $h geq 1$}{
For {$ forall k , 1leq k leq |fn| $}
{Measure $snr^i$ between $fn^k$ and the other sensor nodes $id^i, 1 < i leq
|id^n|$
tcp*{Calculate relay nodes for each hop ($h$)}
$n_h^{fn^k}$ = ${id^j | snr^j geq snr_{thr} & & e^j geq e_{thr} & &
l_z^j leq l_z^{fn^k}, 1< j leq |id^n| }$
tcp*{Calculate possible relay nodes for each $fn^k$}
For{$ forall jj , 1leq jj leq |n_h^{fn^k}| $}{
Calculate $n_{EC}^{jj}$ between $fn^k$ and $n_h^{fn^k}(jj)$
tcp*{Calculate cost function (energy consumption) between $fn^k$
and its possible relay nodes $n_h^{fn^k}$}
}
Update $L{:,h} leftarrow {n_h^{fn^k}}$
tcp*{Update $L{:,h}$ with $n_h^{fn^k}$ for each $fn^k$}
$RC{:,h} leftarrow {n_{EC}+RC{:,h-1} }$
tcp*{Update RC with the EC of new possible next relay nodes}
}
Update $fn leftarrow L{:,h}$
For{$ forall t , 1leq t leq |fn| $}
{tcp*{Check if reach sink node in the forwarding nodes $fn$}
If {$(fn^t == S_{id}$)}{
tcp*{Stop while loop as reach to the sink node}
$R_{sink} leftarrow fn^t$
$R_{sink-rc} leftarrow determine RC of R_{sink}$
}
}
If{$|R_{sink}|geq 1 $}{
Break While
}
$hleftarrow h+1$ tcp*{Increase h until reach $S_{id}$}
}
tcp*{backtrace to select the optimized routing path with minimum RC}
$S^*leftarrow relay_{sink}(argmin_h R_{sink-RC}) $
tcp*{determine the best relay node to $S_id$}
For{$ forall x , h-1 leq x leq 1 $}{
$S^*leftarrow L{:,(argmin_x RC{:,x}) } $
}
Stop
caption{Routing Path Selection Algorithm}
end{algorithm}

algorithms pseudocode
|
show 1 more comment
I need to write the algorithm as formatted in the word. I need to insert initiate statement without taking any numbers, format symbols bold to indicate matrix, change the comments font and change algorithm font size only in the templet. this is the latex code.

begin{algorithm}
label{alg1}
DontPrintSemicolon
SetAlgoLined
SetKwInOut{Input}{Input}
SetKwInOut{Output}{Output}
Input{$e^n,e_{thr},snr_{thr},T_{tx},S_{id},l_x^n,l_y^n,l_z^n$}
Output{Optimized Routing Path for sensor node($S^*$)}
%Intiate{$h=1,RC{:,0}=0,fn=id^1$}
tcp*{$fn$ are the forwarding rely nodes for hop ($h$), $id^1$ is the ID of
source node, $RC$ is the total route cost.}
While{ $h geq 1$}{
For {$ forall k , 1leq k leq |fn| $}
{Measure $snr^i$ between $fn^k$ and the other sensor nodes $id^i, 1 < i leq
|id^n|$
tcp*{Calculate relay nodes for each hop ($h$)}
$n_h^{fn^k}$ = ${id^j | snr^j geq snr_{thr} & & e^j geq e_{thr} & &
l_z^j leq l_z^{fn^k}, 1< j leq |id^n| }$
tcp*{Calculate possible relay nodes for each $fn^k$}
For{$ forall jj , 1leq jj leq |n_h^{fn^k}| $}{
Calculate $n_{EC}^{jj}$ between $fn^k$ and $n_h^{fn^k}(jj)$
tcp*{Calculate cost function (energy consumption) between $fn^k$
and its possible relay nodes $n_h^{fn^k}$}
}
Update $L{:,h} leftarrow {n_h^{fn^k}}$
tcp*{Update $L{:,h}$ with $n_h^{fn^k}$ for each $fn^k$}
$RC{:,h} leftarrow {n_{EC}+RC{:,h-1} }$
tcp*{Update RC with the EC of new possible next relay nodes}
}
Update $fn leftarrow L{:,h}$
For{$ forall t , 1leq t leq |fn| $}
{tcp*{Check if reach sink node in the forwarding nodes $fn$}
If {$(fn^t == S_{id}$)}{
tcp*{Stop while loop as reach to the sink node}
$R_{sink} leftarrow fn^t$
$R_{sink-rc} leftarrow determine RC of R_{sink}$
}
}
If{$|R_{sink}|geq 1 $}{
Break While
}
$hleftarrow h+1$ tcp*{Increase h until reach $S_{id}$}
}
tcp*{backtrace to select the optimized routing path with minimum RC}
$S^*leftarrow relay_{sink}(argmin_h R_{sink-RC}) $
tcp*{determine the best relay node to $S_id$}
For{$ forall x , h-1 leq x leq 1 $}{
$S^*leftarrow L{:,(argmin_x RC{:,x}) } $
}
Stop
caption{Routing Path Selection Algorithm}
end{algorithm}

algorithms pseudocode
1
What have you tried so far? Please add a MWE.
– epR8GaYuh
Jan 8 at 9:32
5
Welcome to TeX.SX and to the LaTeX world in general. Please note that this page is primarily to answer specific questions and not solve do-it-for-me requests. For this reason your question might get closed as it is now. To tackle your issue: there are several packages related to algorithm, e.g.algorithm2e,algorithmicxetc. It would be best if you try to solve this with one of the dedicated packages, and if you encounter problems in the process, feel free to ask specific questions with an MWE.
– Skillmon
Jan 8 at 9:32
@epR8GaYuh begin{algorithm} label{alg1} DontPrintSemicolon SetAlgoLined SetKwInOut{Input}{Input} SetKwInOut{Output}{Output} Input{$e^n,e_{thr},snr_{thr},T_{tx},S_{id},l_x^n,l_y^n,l_z^n$} Output{Optimized Routing Path for sensor node($S^*$)} %Intiate{$h=1,RC{:,0}=0,fn=id^1$} BlankLine While{While condition}{ instructions; eIf{condition}{ instructions1; instructions2; }{ instructions3; } }
– Mona Mostafa
Jan 8 at 10:22
@MonaMostafa Welcome here. You can edit your own post, so you should add this code to your post, not to a comment. Btw, your code is not a complete and compilable MWE.
– JouleV
Jan 8 at 11:16
Adding your current code as an image makes it hard to adapt it without having to re-type everything (in fact you replaced your copyable code with an image of it in a subsequent edit) - as well as the fact that this is no full compilable document.
– epR8GaYuh
Jan 8 at 17:01
|
show 1 more comment
I need to write the algorithm as formatted in the word. I need to insert initiate statement without taking any numbers, format symbols bold to indicate matrix, change the comments font and change algorithm font size only in the templet. this is the latex code.

begin{algorithm}
label{alg1}
DontPrintSemicolon
SetAlgoLined
SetKwInOut{Input}{Input}
SetKwInOut{Output}{Output}
Input{$e^n,e_{thr},snr_{thr},T_{tx},S_{id},l_x^n,l_y^n,l_z^n$}
Output{Optimized Routing Path for sensor node($S^*$)}
%Intiate{$h=1,RC{:,0}=0,fn=id^1$}
tcp*{$fn$ are the forwarding rely nodes for hop ($h$), $id^1$ is the ID of
source node, $RC$ is the total route cost.}
While{ $h geq 1$}{
For {$ forall k , 1leq k leq |fn| $}
{Measure $snr^i$ between $fn^k$ and the other sensor nodes $id^i, 1 < i leq
|id^n|$
tcp*{Calculate relay nodes for each hop ($h$)}
$n_h^{fn^k}$ = ${id^j | snr^j geq snr_{thr} & & e^j geq e_{thr} & &
l_z^j leq l_z^{fn^k}, 1< j leq |id^n| }$
tcp*{Calculate possible relay nodes for each $fn^k$}
For{$ forall jj , 1leq jj leq |n_h^{fn^k}| $}{
Calculate $n_{EC}^{jj}$ between $fn^k$ and $n_h^{fn^k}(jj)$
tcp*{Calculate cost function (energy consumption) between $fn^k$
and its possible relay nodes $n_h^{fn^k}$}
}
Update $L{:,h} leftarrow {n_h^{fn^k}}$
tcp*{Update $L{:,h}$ with $n_h^{fn^k}$ for each $fn^k$}
$RC{:,h} leftarrow {n_{EC}+RC{:,h-1} }$
tcp*{Update RC with the EC of new possible next relay nodes}
}
Update $fn leftarrow L{:,h}$
For{$ forall t , 1leq t leq |fn| $}
{tcp*{Check if reach sink node in the forwarding nodes $fn$}
If {$(fn^t == S_{id}$)}{
tcp*{Stop while loop as reach to the sink node}
$R_{sink} leftarrow fn^t$
$R_{sink-rc} leftarrow determine RC of R_{sink}$
}
}
If{$|R_{sink}|geq 1 $}{
Break While
}
$hleftarrow h+1$ tcp*{Increase h until reach $S_{id}$}
}
tcp*{backtrace to select the optimized routing path with minimum RC}
$S^*leftarrow relay_{sink}(argmin_h R_{sink-RC}) $
tcp*{determine the best relay node to $S_id$}
For{$ forall x , h-1 leq x leq 1 $}{
$S^*leftarrow L{:,(argmin_x RC{:,x}) } $
}
Stop
caption{Routing Path Selection Algorithm}
end{algorithm}

algorithms pseudocode
I need to write the algorithm as formatted in the word. I need to insert initiate statement without taking any numbers, format symbols bold to indicate matrix, change the comments font and change algorithm font size only in the templet. this is the latex code.

begin{algorithm}
label{alg1}
DontPrintSemicolon
SetAlgoLined
SetKwInOut{Input}{Input}
SetKwInOut{Output}{Output}
Input{$e^n,e_{thr},snr_{thr},T_{tx},S_{id},l_x^n,l_y^n,l_z^n$}
Output{Optimized Routing Path for sensor node($S^*$)}
%Intiate{$h=1,RC{:,0}=0,fn=id^1$}
tcp*{$fn$ are the forwarding rely nodes for hop ($h$), $id^1$ is the ID of
source node, $RC$ is the total route cost.}
While{ $h geq 1$}{
For {$ forall k , 1leq k leq |fn| $}
{Measure $snr^i$ between $fn^k$ and the other sensor nodes $id^i, 1 < i leq
|id^n|$
tcp*{Calculate relay nodes for each hop ($h$)}
$n_h^{fn^k}$ = ${id^j | snr^j geq snr_{thr} & & e^j geq e_{thr} & &
l_z^j leq l_z^{fn^k}, 1< j leq |id^n| }$
tcp*{Calculate possible relay nodes for each $fn^k$}
For{$ forall jj , 1leq jj leq |n_h^{fn^k}| $}{
Calculate $n_{EC}^{jj}$ between $fn^k$ and $n_h^{fn^k}(jj)$
tcp*{Calculate cost function (energy consumption) between $fn^k$
and its possible relay nodes $n_h^{fn^k}$}
}
Update $L{:,h} leftarrow {n_h^{fn^k}}$
tcp*{Update $L{:,h}$ with $n_h^{fn^k}$ for each $fn^k$}
$RC{:,h} leftarrow {n_{EC}+RC{:,h-1} }$
tcp*{Update RC with the EC of new possible next relay nodes}
}
Update $fn leftarrow L{:,h}$
For{$ forall t , 1leq t leq |fn| $}
{tcp*{Check if reach sink node in the forwarding nodes $fn$}
If {$(fn^t == S_{id}$)}{
tcp*{Stop while loop as reach to the sink node}
$R_{sink} leftarrow fn^t$
$R_{sink-rc} leftarrow determine RC of R_{sink}$
}
}
If{$|R_{sink}|geq 1 $}{
Break While
}
$hleftarrow h+1$ tcp*{Increase h until reach $S_{id}$}
}
tcp*{backtrace to select the optimized routing path with minimum RC}
$S^*leftarrow relay_{sink}(argmin_h R_{sink-RC}) $
tcp*{determine the best relay node to $S_id$}
For{$ forall x , h-1 leq x leq 1 $}{
$S^*leftarrow L{:,(argmin_x RC{:,x}) } $
}
Stop
caption{Routing Path Selection Algorithm}
end{algorithm}

algorithms pseudocode
algorithms pseudocode
edited Jan 8 at 17:29
Mona Mostafa
asked Jan 8 at 9:29
Mona MostafaMona Mostafa
63
63
1
What have you tried so far? Please add a MWE.
– epR8GaYuh
Jan 8 at 9:32
5
Welcome to TeX.SX and to the LaTeX world in general. Please note that this page is primarily to answer specific questions and not solve do-it-for-me requests. For this reason your question might get closed as it is now. To tackle your issue: there are several packages related to algorithm, e.g.algorithm2e,algorithmicxetc. It would be best if you try to solve this with one of the dedicated packages, and if you encounter problems in the process, feel free to ask specific questions with an MWE.
– Skillmon
Jan 8 at 9:32
@epR8GaYuh begin{algorithm} label{alg1} DontPrintSemicolon SetAlgoLined SetKwInOut{Input}{Input} SetKwInOut{Output}{Output} Input{$e^n,e_{thr},snr_{thr},T_{tx},S_{id},l_x^n,l_y^n,l_z^n$} Output{Optimized Routing Path for sensor node($S^*$)} %Intiate{$h=1,RC{:,0}=0,fn=id^1$} BlankLine While{While condition}{ instructions; eIf{condition}{ instructions1; instructions2; }{ instructions3; } }
– Mona Mostafa
Jan 8 at 10:22
@MonaMostafa Welcome here. You can edit your own post, so you should add this code to your post, not to a comment. Btw, your code is not a complete and compilable MWE.
– JouleV
Jan 8 at 11:16
Adding your current code as an image makes it hard to adapt it without having to re-type everything (in fact you replaced your copyable code with an image of it in a subsequent edit) - as well as the fact that this is no full compilable document.
– epR8GaYuh
Jan 8 at 17:01
|
show 1 more comment
1
What have you tried so far? Please add a MWE.
– epR8GaYuh
Jan 8 at 9:32
5
Welcome to TeX.SX and to the LaTeX world in general. Please note that this page is primarily to answer specific questions and not solve do-it-for-me requests. For this reason your question might get closed as it is now. To tackle your issue: there are several packages related to algorithm, e.g.algorithm2e,algorithmicxetc. It would be best if you try to solve this with one of the dedicated packages, and if you encounter problems in the process, feel free to ask specific questions with an MWE.
– Skillmon
Jan 8 at 9:32
@epR8GaYuh begin{algorithm} label{alg1} DontPrintSemicolon SetAlgoLined SetKwInOut{Input}{Input} SetKwInOut{Output}{Output} Input{$e^n,e_{thr},snr_{thr},T_{tx},S_{id},l_x^n,l_y^n,l_z^n$} Output{Optimized Routing Path for sensor node($S^*$)} %Intiate{$h=1,RC{:,0}=0,fn=id^1$} BlankLine While{While condition}{ instructions; eIf{condition}{ instructions1; instructions2; }{ instructions3; } }
– Mona Mostafa
Jan 8 at 10:22
@MonaMostafa Welcome here. You can edit your own post, so you should add this code to your post, not to a comment. Btw, your code is not a complete and compilable MWE.
– JouleV
Jan 8 at 11:16
Adding your current code as an image makes it hard to adapt it without having to re-type everything (in fact you replaced your copyable code with an image of it in a subsequent edit) - as well as the fact that this is no full compilable document.
– epR8GaYuh
Jan 8 at 17:01
1
1
What have you tried so far? Please add a MWE.
– epR8GaYuh
Jan 8 at 9:32
What have you tried so far? Please add a MWE.
– epR8GaYuh
Jan 8 at 9:32
5
5
Welcome to TeX.SX and to the LaTeX world in general. Please note that this page is primarily to answer specific questions and not solve do-it-for-me requests. For this reason your question might get closed as it is now. To tackle your issue: there are several packages related to algorithm, e.g.
algorithm2e, algorithmicx etc. It would be best if you try to solve this with one of the dedicated packages, and if you encounter problems in the process, feel free to ask specific questions with an MWE.– Skillmon
Jan 8 at 9:32
Welcome to TeX.SX and to the LaTeX world in general. Please note that this page is primarily to answer specific questions and not solve do-it-for-me requests. For this reason your question might get closed as it is now. To tackle your issue: there are several packages related to algorithm, e.g.
algorithm2e, algorithmicx etc. It would be best if you try to solve this with one of the dedicated packages, and if you encounter problems in the process, feel free to ask specific questions with an MWE.– Skillmon
Jan 8 at 9:32
@epR8GaYuh begin{algorithm} label{alg1} DontPrintSemicolon SetAlgoLined SetKwInOut{Input}{Input} SetKwInOut{Output}{Output} Input{$e^n,e_{thr},snr_{thr},T_{tx},S_{id},l_x^n,l_y^n,l_z^n$} Output{Optimized Routing Path for sensor node($S^*$)} %Intiate{$h=1,RC{:,0}=0,fn=id^1$} BlankLine While{While condition}{ instructions; eIf{condition}{ instructions1; instructions2; }{ instructions3; } }
– Mona Mostafa
Jan 8 at 10:22
@epR8GaYuh begin{algorithm} label{alg1} DontPrintSemicolon SetAlgoLined SetKwInOut{Input}{Input} SetKwInOut{Output}{Output} Input{$e^n,e_{thr},snr_{thr},T_{tx},S_{id},l_x^n,l_y^n,l_z^n$} Output{Optimized Routing Path for sensor node($S^*$)} %Intiate{$h=1,RC{:,0}=0,fn=id^1$} BlankLine While{While condition}{ instructions; eIf{condition}{ instructions1; instructions2; }{ instructions3; } }
– Mona Mostafa
Jan 8 at 10:22
@MonaMostafa Welcome here. You can edit your own post, so you should add this code to your post, not to a comment. Btw, your code is not a complete and compilable MWE.
– JouleV
Jan 8 at 11:16
@MonaMostafa Welcome here. You can edit your own post, so you should add this code to your post, not to a comment. Btw, your code is not a complete and compilable MWE.
– JouleV
Jan 8 at 11:16
Adding your current code as an image makes it hard to adapt it without having to re-type everything (in fact you replaced your copyable code with an image of it in a subsequent edit) - as well as the fact that this is no full compilable document.
– epR8GaYuh
Jan 8 at 17:01
Adding your current code as an image makes it hard to adapt it without having to re-type everything (in fact you replaced your copyable code with an image of it in a subsequent edit) - as well as the fact that this is no full compilable document.
– epR8GaYuh
Jan 8 at 17:01
|
show 1 more comment
0
active
oldest
votes
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "85"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f469108%2fformatting-pseudo-code-algorithm%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to TeX - LaTeX Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f469108%2fformatting-pseudo-code-algorithm%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
What have you tried so far? Please add a MWE.
– epR8GaYuh
Jan 8 at 9:32
5
Welcome to TeX.SX and to the LaTeX world in general. Please note that this page is primarily to answer specific questions and not solve do-it-for-me requests. For this reason your question might get closed as it is now. To tackle your issue: there are several packages related to algorithm, e.g.
algorithm2e,algorithmicxetc. It would be best if you try to solve this with one of the dedicated packages, and if you encounter problems in the process, feel free to ask specific questions with an MWE.– Skillmon
Jan 8 at 9:32
@epR8GaYuh begin{algorithm} label{alg1} DontPrintSemicolon SetAlgoLined SetKwInOut{Input}{Input} SetKwInOut{Output}{Output} Input{$e^n,e_{thr},snr_{thr},T_{tx},S_{id},l_x^n,l_y^n,l_z^n$} Output{Optimized Routing Path for sensor node($S^*$)} %Intiate{$h=1,RC{:,0}=0,fn=id^1$} BlankLine While{While condition}{ instructions; eIf{condition}{ instructions1; instructions2; }{ instructions3; } }
– Mona Mostafa
Jan 8 at 10:22
@MonaMostafa Welcome here. You can edit your own post, so you should add this code to your post, not to a comment. Btw, your code is not a complete and compilable MWE.
– JouleV
Jan 8 at 11:16
Adding your current code as an image makes it hard to adapt it without having to re-type everything (in fact you replaced your copyable code with an image of it in a subsequent edit) - as well as the fact that this is no full compilable document.
– epR8GaYuh
Jan 8 at 17:01