Algorithm inside a tcolorbox: how to put a label to the algorithm but the caption as title of tcolorbox?
up vote
2
down vote
favorite
This question comes after a question about algorithms inside tcolorboxes.
Before the question, is better to explain what I have now. I have a file with the algorithm that is q-learning.tex
.
documentclass{standalone}
usepackage[utf8]{inputenc}
usepackage[longend]{algorithm2e}
usepackage{textgreek}
usepackage{amssymb}
begin{document}
begin{algorithm}[H]
Algorithm parameters: step size $alpha in (0, 1]$;
Initialize $Q(s, a)$, for all $s in mathcal{S}^+, a in mathcal{A}(s)$, arbitrarily except that $Q(mathrm{terminal}, cdot) = 0$;
ForEach{episode}{
Initialize S;
ForEach{step of episode}{
Choose $A$ from $S$ using policy derived from $Q$ (e.g. textepsilon-greedy);
Take action $A$, observe $R$, $S'$;
$Q(S, A) leftarrow Q(S, A) + alpha [R + gamma max_a Q(S', a) - Q(S, A)]$;
$S leftarrow S'$;
}
}
end{algorithm}
end{document}
And I include it in my main file with standalone
package.
documentclass{book}
usepackage[utf8]{inputenc}
usepackage[subpreambles,sort]{standalone}
usepackage{tcolorbox}
usepackage{algorithm2e}
begin{document}
begin{tcolorbox}[fonttitle=bfseries, title=Q-learning for estimating $pi approx pi^*$]
input{q-learning}
end{tcolorbox}
end{document}
And the cropped result is like this.
The reason why I need to load algorithm2e
again is obscure to me but it's not what bothers me now. I wish to number the algorithms and then listing them with listofalgorithms
and I want also the possibility to refer to this kind of figures. However, in this implementation, I have no caption and I don't know where to put it. The caption should be the title
field of the tcolorbox
, i.e. the title should be displayed like "Algorithm 3.2 Q-learning for..." but the label should refer to the algorithm that is inside.
So, to summarize:
- The label should refer to the algorithm and I should have the possibility to make a list of algorithms with
listofalgorithms
. - The caption of the algorithm should be displayed as the title of the
tcolorbox
The best change I've made so far is to insert a blank caption and a label inside the algorithm and referring it in the title. It also shows correctly in the list of algorithms. However, I'm not able to remove the annoying "Algorithm 1:" at the bottom.
This is the visual effect:
And this is the code:
q-learning.tex
documentclass{standalone}
usepackage[utf8]{inputenc}
usepackage[longend]{algorithm2e}
usepackage{textgreek}
usepackage{amssymb}
begin{document}
begin{algorithm}[H]
Algorithm parameters: step size $alpha in (0, 1]$;
Initialize $Q(s, a)$, for all $s in mathcal{S}^+, a in mathcal{A}(s)$, arbitrarily except that $Q(mathrm{terminal}, cdot) = 0$;
ForEach{episode}{
Initialize S;
ForEach{step of episode}{
Choose $A$ from $S$ using policy derived from $Q$ (e.g. textepsilon-greedy);
Take action $A$, observe $R$, $S'$;
$Q(S, A) leftarrow Q(S, A) + alpha [R + gamma max_a Q(S', a) - Q(S, A)]$;
$S leftarrow S'$;
}
}
caption[Q-learning for estimating $pi approx pi^*$]{}
label{alg:q-learning}
end{algorithm}
end{document}
main.tex
documentclass{book}
usepackage[utf8]{inputenc}
usepackage[subpreambles,sort]{standalone}
usepackage{tcolorbox}
usepackage{algorithm2e}
begin{document}
frontmatter
listofalgorithms
mainmatter
chapter{First chapter}
begin{tcolorbox}[fonttitle=bfseries, title=Algorithm ref{alg:q-learning}: Q-learning for estimating $pi approx pi^*$]
input{q-learning}
end{tcolorbox}
end{document}
Of course, the result unitl now is not suitable for my needs.
captions tcolorbox labels algorithm2e
add a comment |
up vote
2
down vote
favorite
This question comes after a question about algorithms inside tcolorboxes.
Before the question, is better to explain what I have now. I have a file with the algorithm that is q-learning.tex
.
documentclass{standalone}
usepackage[utf8]{inputenc}
usepackage[longend]{algorithm2e}
usepackage{textgreek}
usepackage{amssymb}
begin{document}
begin{algorithm}[H]
Algorithm parameters: step size $alpha in (0, 1]$;
Initialize $Q(s, a)$, for all $s in mathcal{S}^+, a in mathcal{A}(s)$, arbitrarily except that $Q(mathrm{terminal}, cdot) = 0$;
ForEach{episode}{
Initialize S;
ForEach{step of episode}{
Choose $A$ from $S$ using policy derived from $Q$ (e.g. textepsilon-greedy);
Take action $A$, observe $R$, $S'$;
$Q(S, A) leftarrow Q(S, A) + alpha [R + gamma max_a Q(S', a) - Q(S, A)]$;
$S leftarrow S'$;
}
}
end{algorithm}
end{document}
And I include it in my main file with standalone
package.
documentclass{book}
usepackage[utf8]{inputenc}
usepackage[subpreambles,sort]{standalone}
usepackage{tcolorbox}
usepackage{algorithm2e}
begin{document}
begin{tcolorbox}[fonttitle=bfseries, title=Q-learning for estimating $pi approx pi^*$]
input{q-learning}
end{tcolorbox}
end{document}
And the cropped result is like this.
The reason why I need to load algorithm2e
again is obscure to me but it's not what bothers me now. I wish to number the algorithms and then listing them with listofalgorithms
and I want also the possibility to refer to this kind of figures. However, in this implementation, I have no caption and I don't know where to put it. The caption should be the title
field of the tcolorbox
, i.e. the title should be displayed like "Algorithm 3.2 Q-learning for..." but the label should refer to the algorithm that is inside.
So, to summarize:
- The label should refer to the algorithm and I should have the possibility to make a list of algorithms with
listofalgorithms
. - The caption of the algorithm should be displayed as the title of the
tcolorbox
The best change I've made so far is to insert a blank caption and a label inside the algorithm and referring it in the title. It also shows correctly in the list of algorithms. However, I'm not able to remove the annoying "Algorithm 1:" at the bottom.
This is the visual effect:
And this is the code:
q-learning.tex
documentclass{standalone}
usepackage[utf8]{inputenc}
usepackage[longend]{algorithm2e}
usepackage{textgreek}
usepackage{amssymb}
begin{document}
begin{algorithm}[H]
Algorithm parameters: step size $alpha in (0, 1]$;
Initialize $Q(s, a)$, for all $s in mathcal{S}^+, a in mathcal{A}(s)$, arbitrarily except that $Q(mathrm{terminal}, cdot) = 0$;
ForEach{episode}{
Initialize S;
ForEach{step of episode}{
Choose $A$ from $S$ using policy derived from $Q$ (e.g. textepsilon-greedy);
Take action $A$, observe $R$, $S'$;
$Q(S, A) leftarrow Q(S, A) + alpha [R + gamma max_a Q(S', a) - Q(S, A)]$;
$S leftarrow S'$;
}
}
caption[Q-learning for estimating $pi approx pi^*$]{}
label{alg:q-learning}
end{algorithm}
end{document}
main.tex
documentclass{book}
usepackage[utf8]{inputenc}
usepackage[subpreambles,sort]{standalone}
usepackage{tcolorbox}
usepackage{algorithm2e}
begin{document}
frontmatter
listofalgorithms
mainmatter
chapter{First chapter}
begin{tcolorbox}[fonttitle=bfseries, title=Algorithm ref{alg:q-learning}: Q-learning for estimating $pi approx pi^*$]
input{q-learning}
end{tcolorbox}
end{document}
Of course, the result unitl now is not suitable for my needs.
captions tcolorbox labels algorithm2e
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
This question comes after a question about algorithms inside tcolorboxes.
Before the question, is better to explain what I have now. I have a file with the algorithm that is q-learning.tex
.
documentclass{standalone}
usepackage[utf8]{inputenc}
usepackage[longend]{algorithm2e}
usepackage{textgreek}
usepackage{amssymb}
begin{document}
begin{algorithm}[H]
Algorithm parameters: step size $alpha in (0, 1]$;
Initialize $Q(s, a)$, for all $s in mathcal{S}^+, a in mathcal{A}(s)$, arbitrarily except that $Q(mathrm{terminal}, cdot) = 0$;
ForEach{episode}{
Initialize S;
ForEach{step of episode}{
Choose $A$ from $S$ using policy derived from $Q$ (e.g. textepsilon-greedy);
Take action $A$, observe $R$, $S'$;
$Q(S, A) leftarrow Q(S, A) + alpha [R + gamma max_a Q(S', a) - Q(S, A)]$;
$S leftarrow S'$;
}
}
end{algorithm}
end{document}
And I include it in my main file with standalone
package.
documentclass{book}
usepackage[utf8]{inputenc}
usepackage[subpreambles,sort]{standalone}
usepackage{tcolorbox}
usepackage{algorithm2e}
begin{document}
begin{tcolorbox}[fonttitle=bfseries, title=Q-learning for estimating $pi approx pi^*$]
input{q-learning}
end{tcolorbox}
end{document}
And the cropped result is like this.
The reason why I need to load algorithm2e
again is obscure to me but it's not what bothers me now. I wish to number the algorithms and then listing them with listofalgorithms
and I want also the possibility to refer to this kind of figures. However, in this implementation, I have no caption and I don't know where to put it. The caption should be the title
field of the tcolorbox
, i.e. the title should be displayed like "Algorithm 3.2 Q-learning for..." but the label should refer to the algorithm that is inside.
So, to summarize:
- The label should refer to the algorithm and I should have the possibility to make a list of algorithms with
listofalgorithms
. - The caption of the algorithm should be displayed as the title of the
tcolorbox
The best change I've made so far is to insert a blank caption and a label inside the algorithm and referring it in the title. It also shows correctly in the list of algorithms. However, I'm not able to remove the annoying "Algorithm 1:" at the bottom.
This is the visual effect:
And this is the code:
q-learning.tex
documentclass{standalone}
usepackage[utf8]{inputenc}
usepackage[longend]{algorithm2e}
usepackage{textgreek}
usepackage{amssymb}
begin{document}
begin{algorithm}[H]
Algorithm parameters: step size $alpha in (0, 1]$;
Initialize $Q(s, a)$, for all $s in mathcal{S}^+, a in mathcal{A}(s)$, arbitrarily except that $Q(mathrm{terminal}, cdot) = 0$;
ForEach{episode}{
Initialize S;
ForEach{step of episode}{
Choose $A$ from $S$ using policy derived from $Q$ (e.g. textepsilon-greedy);
Take action $A$, observe $R$, $S'$;
$Q(S, A) leftarrow Q(S, A) + alpha [R + gamma max_a Q(S', a) - Q(S, A)]$;
$S leftarrow S'$;
}
}
caption[Q-learning for estimating $pi approx pi^*$]{}
label{alg:q-learning}
end{algorithm}
end{document}
main.tex
documentclass{book}
usepackage[utf8]{inputenc}
usepackage[subpreambles,sort]{standalone}
usepackage{tcolorbox}
usepackage{algorithm2e}
begin{document}
frontmatter
listofalgorithms
mainmatter
chapter{First chapter}
begin{tcolorbox}[fonttitle=bfseries, title=Algorithm ref{alg:q-learning}: Q-learning for estimating $pi approx pi^*$]
input{q-learning}
end{tcolorbox}
end{document}
Of course, the result unitl now is not suitable for my needs.
captions tcolorbox labels algorithm2e
This question comes after a question about algorithms inside tcolorboxes.
Before the question, is better to explain what I have now. I have a file with the algorithm that is q-learning.tex
.
documentclass{standalone}
usepackage[utf8]{inputenc}
usepackage[longend]{algorithm2e}
usepackage{textgreek}
usepackage{amssymb}
begin{document}
begin{algorithm}[H]
Algorithm parameters: step size $alpha in (0, 1]$;
Initialize $Q(s, a)$, for all $s in mathcal{S}^+, a in mathcal{A}(s)$, arbitrarily except that $Q(mathrm{terminal}, cdot) = 0$;
ForEach{episode}{
Initialize S;
ForEach{step of episode}{
Choose $A$ from $S$ using policy derived from $Q$ (e.g. textepsilon-greedy);
Take action $A$, observe $R$, $S'$;
$Q(S, A) leftarrow Q(S, A) + alpha [R + gamma max_a Q(S', a) - Q(S, A)]$;
$S leftarrow S'$;
}
}
end{algorithm}
end{document}
And I include it in my main file with standalone
package.
documentclass{book}
usepackage[utf8]{inputenc}
usepackage[subpreambles,sort]{standalone}
usepackage{tcolorbox}
usepackage{algorithm2e}
begin{document}
begin{tcolorbox}[fonttitle=bfseries, title=Q-learning for estimating $pi approx pi^*$]
input{q-learning}
end{tcolorbox}
end{document}
And the cropped result is like this.
The reason why I need to load algorithm2e
again is obscure to me but it's not what bothers me now. I wish to number the algorithms and then listing them with listofalgorithms
and I want also the possibility to refer to this kind of figures. However, in this implementation, I have no caption and I don't know where to put it. The caption should be the title
field of the tcolorbox
, i.e. the title should be displayed like "Algorithm 3.2 Q-learning for..." but the label should refer to the algorithm that is inside.
So, to summarize:
- The label should refer to the algorithm and I should have the possibility to make a list of algorithms with
listofalgorithms
. - The caption of the algorithm should be displayed as the title of the
tcolorbox
The best change I've made so far is to insert a blank caption and a label inside the algorithm and referring it in the title. It also shows correctly in the list of algorithms. However, I'm not able to remove the annoying "Algorithm 1:" at the bottom.
This is the visual effect:
And this is the code:
q-learning.tex
documentclass{standalone}
usepackage[utf8]{inputenc}
usepackage[longend]{algorithm2e}
usepackage{textgreek}
usepackage{amssymb}
begin{document}
begin{algorithm}[H]
Algorithm parameters: step size $alpha in (0, 1]$;
Initialize $Q(s, a)$, for all $s in mathcal{S}^+, a in mathcal{A}(s)$, arbitrarily except that $Q(mathrm{terminal}, cdot) = 0$;
ForEach{episode}{
Initialize S;
ForEach{step of episode}{
Choose $A$ from $S$ using policy derived from $Q$ (e.g. textepsilon-greedy);
Take action $A$, observe $R$, $S'$;
$Q(S, A) leftarrow Q(S, A) + alpha [R + gamma max_a Q(S', a) - Q(S, A)]$;
$S leftarrow S'$;
}
}
caption[Q-learning for estimating $pi approx pi^*$]{}
label{alg:q-learning}
end{algorithm}
end{document}
main.tex
documentclass{book}
usepackage[utf8]{inputenc}
usepackage[subpreambles,sort]{standalone}
usepackage{tcolorbox}
usepackage{algorithm2e}
begin{document}
frontmatter
listofalgorithms
mainmatter
chapter{First chapter}
begin{tcolorbox}[fonttitle=bfseries, title=Algorithm ref{alg:q-learning}: Q-learning for estimating $pi approx pi^*$]
input{q-learning}
end{tcolorbox}
end{document}
Of course, the result unitl now is not suitable for my needs.
captions tcolorbox labels algorithm2e
captions tcolorbox labels algorithm2e
edited Dec 6 at 8:56
asked Dec 5 at 18:22
gvgramazio
1,415520
1,415520
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
Found a solution. It's not perfect but do the job.
q-learning.tex
documentclass{standalone}
usepackage[utf8]{inputenc}
usepackage[longend]{algorithm2e}
usepackage{textgreek}
usepackage{amssymb}
begin{document}
begin{algorithm}[H]
Algorithm parameters: step size $alpha in (0, 1]$;
Initialize $Q(s, a)$, for all $s in mathcal{S}^+, a in mathcal{A}(s)$, arbitrarily except that $Q(mathrm{terminal}, cdot) = 0$;
ForEach{episode}{
Initialize S;
ForEach{step of episode}{
Choose $A$ from $S$ using policy derived from $Q$ (e.g. textepsilon-greedy);
Take action $A$, observe $R$, $S'$;
$Q(S, A) leftarrow Q(S, A) + alpha [R + gamma max_a Q(S', a) - Q(S, A)]$;
$S leftarrow S'$;
}
}
caption[Q-learning for estimating $pi approx pi^*$]{}
label{alg:q-learning}
end{algorithm}
end{document}
main.tex
documentclass{book}
usepackage[utf8]{inputenc}
usepackage[subpreambles,sort]{standalone}
usepackage{tcolorbox}
usepackage{algorithm2e}
NoCaptionOfAlgo
usepackage{hyperref}
begin{document}
frontmatter
listofalgorithms
mainmatter
chapter{First chapter}
begin{tcolorbox}[fonttitle=bfseries, title=Algorithm~ref*{alg:q-learning}: Q-learning for estimating $pi approx pi^*$]
input{q-learning}
end{tcolorbox}
end{document}
Basically, it works in this way:
NoCaptionOfAlgo
doesn’t print Algorithm and its number in the caption. This macro is ONLY active for "algoruled" or "ruled" algorithms (see documentation).- In the algorithm, I set only the label and the optional parameter of
caption
. The first for reference, the second to be displayed in the list of algorithms printed withlistofalgorithms
. - I manually type the caption prefix in the title of tcolorbox together with the number of the algorithm. If the package
hyperref
is loaded, I suggest using the starred version ofref
to avoid hyperlink.
The solution works fine. The only thing that doesn't satisfy me is the last point: the title, the reference and the caption prefix in the title are all set manually. This means that is prone to errors. If anyone comes with a better, automated solution I will appreciate it.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
Found a solution. It's not perfect but do the job.
q-learning.tex
documentclass{standalone}
usepackage[utf8]{inputenc}
usepackage[longend]{algorithm2e}
usepackage{textgreek}
usepackage{amssymb}
begin{document}
begin{algorithm}[H]
Algorithm parameters: step size $alpha in (0, 1]$;
Initialize $Q(s, a)$, for all $s in mathcal{S}^+, a in mathcal{A}(s)$, arbitrarily except that $Q(mathrm{terminal}, cdot) = 0$;
ForEach{episode}{
Initialize S;
ForEach{step of episode}{
Choose $A$ from $S$ using policy derived from $Q$ (e.g. textepsilon-greedy);
Take action $A$, observe $R$, $S'$;
$Q(S, A) leftarrow Q(S, A) + alpha [R + gamma max_a Q(S', a) - Q(S, A)]$;
$S leftarrow S'$;
}
}
caption[Q-learning for estimating $pi approx pi^*$]{}
label{alg:q-learning}
end{algorithm}
end{document}
main.tex
documentclass{book}
usepackage[utf8]{inputenc}
usepackage[subpreambles,sort]{standalone}
usepackage{tcolorbox}
usepackage{algorithm2e}
NoCaptionOfAlgo
usepackage{hyperref}
begin{document}
frontmatter
listofalgorithms
mainmatter
chapter{First chapter}
begin{tcolorbox}[fonttitle=bfseries, title=Algorithm~ref*{alg:q-learning}: Q-learning for estimating $pi approx pi^*$]
input{q-learning}
end{tcolorbox}
end{document}
Basically, it works in this way:
NoCaptionOfAlgo
doesn’t print Algorithm and its number in the caption. This macro is ONLY active for "algoruled" or "ruled" algorithms (see documentation).- In the algorithm, I set only the label and the optional parameter of
caption
. The first for reference, the second to be displayed in the list of algorithms printed withlistofalgorithms
. - I manually type the caption prefix in the title of tcolorbox together with the number of the algorithm. If the package
hyperref
is loaded, I suggest using the starred version ofref
to avoid hyperlink.
The solution works fine. The only thing that doesn't satisfy me is the last point: the title, the reference and the caption prefix in the title are all set manually. This means that is prone to errors. If anyone comes with a better, automated solution I will appreciate it.
add a comment |
up vote
1
down vote
accepted
Found a solution. It's not perfect but do the job.
q-learning.tex
documentclass{standalone}
usepackage[utf8]{inputenc}
usepackage[longend]{algorithm2e}
usepackage{textgreek}
usepackage{amssymb}
begin{document}
begin{algorithm}[H]
Algorithm parameters: step size $alpha in (0, 1]$;
Initialize $Q(s, a)$, for all $s in mathcal{S}^+, a in mathcal{A}(s)$, arbitrarily except that $Q(mathrm{terminal}, cdot) = 0$;
ForEach{episode}{
Initialize S;
ForEach{step of episode}{
Choose $A$ from $S$ using policy derived from $Q$ (e.g. textepsilon-greedy);
Take action $A$, observe $R$, $S'$;
$Q(S, A) leftarrow Q(S, A) + alpha [R + gamma max_a Q(S', a) - Q(S, A)]$;
$S leftarrow S'$;
}
}
caption[Q-learning for estimating $pi approx pi^*$]{}
label{alg:q-learning}
end{algorithm}
end{document}
main.tex
documentclass{book}
usepackage[utf8]{inputenc}
usepackage[subpreambles,sort]{standalone}
usepackage{tcolorbox}
usepackage{algorithm2e}
NoCaptionOfAlgo
usepackage{hyperref}
begin{document}
frontmatter
listofalgorithms
mainmatter
chapter{First chapter}
begin{tcolorbox}[fonttitle=bfseries, title=Algorithm~ref*{alg:q-learning}: Q-learning for estimating $pi approx pi^*$]
input{q-learning}
end{tcolorbox}
end{document}
Basically, it works in this way:
NoCaptionOfAlgo
doesn’t print Algorithm and its number in the caption. This macro is ONLY active for "algoruled" or "ruled" algorithms (see documentation).- In the algorithm, I set only the label and the optional parameter of
caption
. The first for reference, the second to be displayed in the list of algorithms printed withlistofalgorithms
. - I manually type the caption prefix in the title of tcolorbox together with the number of the algorithm. If the package
hyperref
is loaded, I suggest using the starred version ofref
to avoid hyperlink.
The solution works fine. The only thing that doesn't satisfy me is the last point: the title, the reference and the caption prefix in the title are all set manually. This means that is prone to errors. If anyone comes with a better, automated solution I will appreciate it.
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
Found a solution. It's not perfect but do the job.
q-learning.tex
documentclass{standalone}
usepackage[utf8]{inputenc}
usepackage[longend]{algorithm2e}
usepackage{textgreek}
usepackage{amssymb}
begin{document}
begin{algorithm}[H]
Algorithm parameters: step size $alpha in (0, 1]$;
Initialize $Q(s, a)$, for all $s in mathcal{S}^+, a in mathcal{A}(s)$, arbitrarily except that $Q(mathrm{terminal}, cdot) = 0$;
ForEach{episode}{
Initialize S;
ForEach{step of episode}{
Choose $A$ from $S$ using policy derived from $Q$ (e.g. textepsilon-greedy);
Take action $A$, observe $R$, $S'$;
$Q(S, A) leftarrow Q(S, A) + alpha [R + gamma max_a Q(S', a) - Q(S, A)]$;
$S leftarrow S'$;
}
}
caption[Q-learning for estimating $pi approx pi^*$]{}
label{alg:q-learning}
end{algorithm}
end{document}
main.tex
documentclass{book}
usepackage[utf8]{inputenc}
usepackage[subpreambles,sort]{standalone}
usepackage{tcolorbox}
usepackage{algorithm2e}
NoCaptionOfAlgo
usepackage{hyperref}
begin{document}
frontmatter
listofalgorithms
mainmatter
chapter{First chapter}
begin{tcolorbox}[fonttitle=bfseries, title=Algorithm~ref*{alg:q-learning}: Q-learning for estimating $pi approx pi^*$]
input{q-learning}
end{tcolorbox}
end{document}
Basically, it works in this way:
NoCaptionOfAlgo
doesn’t print Algorithm and its number in the caption. This macro is ONLY active for "algoruled" or "ruled" algorithms (see documentation).- In the algorithm, I set only the label and the optional parameter of
caption
. The first for reference, the second to be displayed in the list of algorithms printed withlistofalgorithms
. - I manually type the caption prefix in the title of tcolorbox together with the number of the algorithm. If the package
hyperref
is loaded, I suggest using the starred version ofref
to avoid hyperlink.
The solution works fine. The only thing that doesn't satisfy me is the last point: the title, the reference and the caption prefix in the title are all set manually. This means that is prone to errors. If anyone comes with a better, automated solution I will appreciate it.
Found a solution. It's not perfect but do the job.
q-learning.tex
documentclass{standalone}
usepackage[utf8]{inputenc}
usepackage[longend]{algorithm2e}
usepackage{textgreek}
usepackage{amssymb}
begin{document}
begin{algorithm}[H]
Algorithm parameters: step size $alpha in (0, 1]$;
Initialize $Q(s, a)$, for all $s in mathcal{S}^+, a in mathcal{A}(s)$, arbitrarily except that $Q(mathrm{terminal}, cdot) = 0$;
ForEach{episode}{
Initialize S;
ForEach{step of episode}{
Choose $A$ from $S$ using policy derived from $Q$ (e.g. textepsilon-greedy);
Take action $A$, observe $R$, $S'$;
$Q(S, A) leftarrow Q(S, A) + alpha [R + gamma max_a Q(S', a) - Q(S, A)]$;
$S leftarrow S'$;
}
}
caption[Q-learning for estimating $pi approx pi^*$]{}
label{alg:q-learning}
end{algorithm}
end{document}
main.tex
documentclass{book}
usepackage[utf8]{inputenc}
usepackage[subpreambles,sort]{standalone}
usepackage{tcolorbox}
usepackage{algorithm2e}
NoCaptionOfAlgo
usepackage{hyperref}
begin{document}
frontmatter
listofalgorithms
mainmatter
chapter{First chapter}
begin{tcolorbox}[fonttitle=bfseries, title=Algorithm~ref*{alg:q-learning}: Q-learning for estimating $pi approx pi^*$]
input{q-learning}
end{tcolorbox}
end{document}
Basically, it works in this way:
NoCaptionOfAlgo
doesn’t print Algorithm and its number in the caption. This macro is ONLY active for "algoruled" or "ruled" algorithms (see documentation).- In the algorithm, I set only the label and the optional parameter of
caption
. The first for reference, the second to be displayed in the list of algorithms printed withlistofalgorithms
. - I manually type the caption prefix in the title of tcolorbox together with the number of the algorithm. If the package
hyperref
is loaded, I suggest using the starred version ofref
to avoid hyperlink.
The solution works fine. The only thing that doesn't satisfy me is the last point: the title, the reference and the caption prefix in the title are all set manually. This means that is prone to errors. If anyone comes with a better, automated solution I will appreciate it.
answered Dec 7 at 9:18
gvgramazio
1,415520
1,415520
add a comment |
add a comment |
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2f463359%2falgorithm-inside-a-tcolorbox-how-to-put-a-label-to-the-algorithm-but-the-captio%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