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
2












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.



algo



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:



example2



example3



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.










share|improve this question




























    up vote
    2
    down vote

    favorite
    2












    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.



    algo



    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:



    example2



    example3



    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.










    share|improve this question


























      up vote
      2
      down vote

      favorite
      2









      up vote
      2
      down vote

      favorite
      2






      2





      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.



      algo



      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:



      example2



      example3



      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.










      share|improve this question















      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.



      algo



      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:



      example2



      example3



      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 6 at 8:56

























      asked Dec 5 at 18:22









      gvgramazio

      1,415520




      1,415520






















          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 with listofalgorithms.

          • 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 of ref 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.






          share|improve this answer





















            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',
            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
            });


            }
            });














            draft saved

            draft discarded


















            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

























            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 with listofalgorithms.

            • 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 of ref 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.






            share|improve this answer

























              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 with listofalgorithms.

              • 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 of ref 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.






              share|improve this answer























                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 with listofalgorithms.

                • 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 of ref 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.






                share|improve this answer












                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 with listofalgorithms.

                • 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 of ref 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.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Dec 7 at 9:18









                gvgramazio

                1,415520




                1,415520






























                    draft saved

                    draft discarded




















































                    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.




                    draft saved


                    draft discarded














                    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





















































                    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







                    Popular posts from this blog

                    How to change which sound is reproduced for terminal bell?

                    Can I use Tabulator js library in my java Spring + Thymeleaf project?

                    Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents