Auto width tcolorbox around equation












8















I am using tcolorbox to draw boxes around equations. Since the box widths are equal to the equation widths, long titles are often shrunk, hence looking ugly, as shown here:



enter image description here



Is there any way to draw a box of auto-width around the equation and title?



A minimal working example is here:



documentclass[11pt]{article}
usepackage[many]{tcolorbox}

begin{document}
begin{equation}
tcbhighmath[title=A long title hence does not fit]{lambda=at^2}
end{equation}

begin{equation}
tcbhighmath[title=short-title]{lambda=at^2+bt^3}
end{equation}
end{document}









share|improve this question





























    8















    I am using tcolorbox to draw boxes around equations. Since the box widths are equal to the equation widths, long titles are often shrunk, hence looking ugly, as shown here:



    enter image description here



    Is there any way to draw a box of auto-width around the equation and title?



    A minimal working example is here:



    documentclass[11pt]{article}
    usepackage[many]{tcolorbox}

    begin{document}
    begin{equation}
    tcbhighmath[title=A long title hence does not fit]{lambda=at^2}
    end{equation}

    begin{equation}
    tcbhighmath[title=short-title]{lambda=at^2+bt^3}
    end{equation}
    end{document}









    share|improve this question



























      8












      8








      8


      2






      I am using tcolorbox to draw boxes around equations. Since the box widths are equal to the equation widths, long titles are often shrunk, hence looking ugly, as shown here:



      enter image description here



      Is there any way to draw a box of auto-width around the equation and title?



      A minimal working example is here:



      documentclass[11pt]{article}
      usepackage[many]{tcolorbox}

      begin{document}
      begin{equation}
      tcbhighmath[title=A long title hence does not fit]{lambda=at^2}
      end{equation}

      begin{equation}
      tcbhighmath[title=short-title]{lambda=at^2+bt^3}
      end{equation}
      end{document}









      share|improve this question
















      I am using tcolorbox to draw boxes around equations. Since the box widths are equal to the equation widths, long titles are often shrunk, hence looking ugly, as shown here:



      enter image description here



      Is there any way to draw a box of auto-width around the equation and title?



      A minimal working example is here:



      documentclass[11pt]{article}
      usepackage[many]{tcolorbox}

      begin{document}
      begin{equation}
      tcbhighmath[title=A long title hence does not fit]{lambda=at^2}
      end{equation}

      begin{equation}
      tcbhighmath[title=short-title]{lambda=at^2+bt^3}
      end{equation}
      end{document}






      equations tcolorbox width






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 5 at 16:44







      Ashok

















      asked Jan 5 at 16:19









      AshokAshok

      412311




      412311






















          2 Answers
          2






          active

          oldest

          votes


















          8














          A different approach by defining a new key autowidth title that lets the minimum text width to be equal to the the title length



          documentclass[11pt]{article}
          usepackage[many]{tcolorbox}

          pgfkeysdef{/tcb/autowidth title}{
          pgfmathwidth{"#1"}
          defwidth{pgfmathresult pt} % width = title length
          %
          tcbset{title=#1,
          tcbox width=minimum center,
          text width=width % minimum text width = title length
          }
          }

          begin{document}
          begin{equation}
          tcbhighmath[autowidth title=A long title hence does not fit ]{lambda=at^2}
          end{equation}

          begin{equation}
          tcbhighmath[autowidth title=short-title]{lambda=at^2+bt^3}
          end{equation}

          end{document}


          enter image description here






          share|improve this answer





















          • 1





            My compliments for another answer. Very good and I have much appreciated it.

            – Sebastiano
            Jan 5 at 21:54



















          10














          From this excellent macro of Thomas F. Sturm: ....fit the width...., here there is my adapt answer:



          enter image description here



          documentclass[11pt]{article}
          usepackage[many]{tcolorbox}
          tcbset{longtitle/.style={%
          title={#1},
          before upper={begin{tabular}{@{}l@{}l}phantom{#1}\[thedimexpr-htstrutbox-dpstrutbox]},
          after upper={end{tabular}}}
          }

          begin{document}
          begin{equation}
          tcbhighmath[longtitle=A long title hence does now fit]{$lambda=at^2$}%<---- for a double dollar
          end{equation}


          begin{equation}
          tcbhighmath[title=short-title]{lambda=at^2+bt^3}%<---- without a double dollar
          end{equation}
          end{document}


          A fix for avoiding the $ characters in the main argument:



          documentclass[11pt]{article}
          usepackage{array}
          usepackage[many]{tcolorbox}

          tcbset{longtitle/.style={%
          title={#1},
          before upper={%
          $begin{array}{@{}>{displaystyle}l@{}}
          mbox{phantom{#1}}\[thedimexpr-htstrutbox-dpstrutbox]%
          },
          after upper={end{array}$}},
          }

          begin{document}

          begin{equation}
          tcbhighmath[longtitle=A long title hence does now fit]{lambda=at^2}
          end{equation}

          begin{equation}
          tcbhighmath[title=short-title]{lambda=at^2+bt^3}
          end{equation}

          end{document}





          share|improve this answer


























          • @egreg Thank you very much (Tks to infty) for your precious edit.

            – Sebastiano
            Jan 5 at 21:30











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


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f468724%2fauto-width-tcolorbox-around-equation%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          8














          A different approach by defining a new key autowidth title that lets the minimum text width to be equal to the the title length



          documentclass[11pt]{article}
          usepackage[many]{tcolorbox}

          pgfkeysdef{/tcb/autowidth title}{
          pgfmathwidth{"#1"}
          defwidth{pgfmathresult pt} % width = title length
          %
          tcbset{title=#1,
          tcbox width=minimum center,
          text width=width % minimum text width = title length
          }
          }

          begin{document}
          begin{equation}
          tcbhighmath[autowidth title=A long title hence does not fit ]{lambda=at^2}
          end{equation}

          begin{equation}
          tcbhighmath[autowidth title=short-title]{lambda=at^2+bt^3}
          end{equation}

          end{document}


          enter image description here






          share|improve this answer





















          • 1





            My compliments for another answer. Very good and I have much appreciated it.

            – Sebastiano
            Jan 5 at 21:54
















          8














          A different approach by defining a new key autowidth title that lets the minimum text width to be equal to the the title length



          documentclass[11pt]{article}
          usepackage[many]{tcolorbox}

          pgfkeysdef{/tcb/autowidth title}{
          pgfmathwidth{"#1"}
          defwidth{pgfmathresult pt} % width = title length
          %
          tcbset{title=#1,
          tcbox width=minimum center,
          text width=width % minimum text width = title length
          }
          }

          begin{document}
          begin{equation}
          tcbhighmath[autowidth title=A long title hence does not fit ]{lambda=at^2}
          end{equation}

          begin{equation}
          tcbhighmath[autowidth title=short-title]{lambda=at^2+bt^3}
          end{equation}

          end{document}


          enter image description here






          share|improve this answer





















          • 1





            My compliments for another answer. Very good and I have much appreciated it.

            – Sebastiano
            Jan 5 at 21:54














          8












          8








          8







          A different approach by defining a new key autowidth title that lets the minimum text width to be equal to the the title length



          documentclass[11pt]{article}
          usepackage[many]{tcolorbox}

          pgfkeysdef{/tcb/autowidth title}{
          pgfmathwidth{"#1"}
          defwidth{pgfmathresult pt} % width = title length
          %
          tcbset{title=#1,
          tcbox width=minimum center,
          text width=width % minimum text width = title length
          }
          }

          begin{document}
          begin{equation}
          tcbhighmath[autowidth title=A long title hence does not fit ]{lambda=at^2}
          end{equation}

          begin{equation}
          tcbhighmath[autowidth title=short-title]{lambda=at^2+bt^3}
          end{equation}

          end{document}


          enter image description here






          share|improve this answer















          A different approach by defining a new key autowidth title that lets the minimum text width to be equal to the the title length



          documentclass[11pt]{article}
          usepackage[many]{tcolorbox}

          pgfkeysdef{/tcb/autowidth title}{
          pgfmathwidth{"#1"}
          defwidth{pgfmathresult pt} % width = title length
          %
          tcbset{title=#1,
          tcbox width=minimum center,
          text width=width % minimum text width = title length
          }
          }

          begin{document}
          begin{equation}
          tcbhighmath[autowidth title=A long title hence does not fit ]{lambda=at^2}
          end{equation}

          begin{equation}
          tcbhighmath[autowidth title=short-title]{lambda=at^2+bt^3}
          end{equation}

          end{document}


          enter image description here







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Jan 23 at 12:35

























          answered Jan 5 at 21:52









          Hafid BoukhouldaHafid Boukhoulda

          4,5741625




          4,5741625








          • 1





            My compliments for another answer. Very good and I have much appreciated it.

            – Sebastiano
            Jan 5 at 21:54














          • 1





            My compliments for another answer. Very good and I have much appreciated it.

            – Sebastiano
            Jan 5 at 21:54








          1




          1





          My compliments for another answer. Very good and I have much appreciated it.

          – Sebastiano
          Jan 5 at 21:54





          My compliments for another answer. Very good and I have much appreciated it.

          – Sebastiano
          Jan 5 at 21:54











          10














          From this excellent macro of Thomas F. Sturm: ....fit the width...., here there is my adapt answer:



          enter image description here



          documentclass[11pt]{article}
          usepackage[many]{tcolorbox}
          tcbset{longtitle/.style={%
          title={#1},
          before upper={begin{tabular}{@{}l@{}l}phantom{#1}\[thedimexpr-htstrutbox-dpstrutbox]},
          after upper={end{tabular}}}
          }

          begin{document}
          begin{equation}
          tcbhighmath[longtitle=A long title hence does now fit]{$lambda=at^2$}%<---- for a double dollar
          end{equation}


          begin{equation}
          tcbhighmath[title=short-title]{lambda=at^2+bt^3}%<---- without a double dollar
          end{equation}
          end{document}


          A fix for avoiding the $ characters in the main argument:



          documentclass[11pt]{article}
          usepackage{array}
          usepackage[many]{tcolorbox}

          tcbset{longtitle/.style={%
          title={#1},
          before upper={%
          $begin{array}{@{}>{displaystyle}l@{}}
          mbox{phantom{#1}}\[thedimexpr-htstrutbox-dpstrutbox]%
          },
          after upper={end{array}$}},
          }

          begin{document}

          begin{equation}
          tcbhighmath[longtitle=A long title hence does now fit]{lambda=at^2}
          end{equation}

          begin{equation}
          tcbhighmath[title=short-title]{lambda=at^2+bt^3}
          end{equation}

          end{document}





          share|improve this answer


























          • @egreg Thank you very much (Tks to infty) for your precious edit.

            – Sebastiano
            Jan 5 at 21:30
















          10














          From this excellent macro of Thomas F. Sturm: ....fit the width...., here there is my adapt answer:



          enter image description here



          documentclass[11pt]{article}
          usepackage[many]{tcolorbox}
          tcbset{longtitle/.style={%
          title={#1},
          before upper={begin{tabular}{@{}l@{}l}phantom{#1}\[thedimexpr-htstrutbox-dpstrutbox]},
          after upper={end{tabular}}}
          }

          begin{document}
          begin{equation}
          tcbhighmath[longtitle=A long title hence does now fit]{$lambda=at^2$}%<---- for a double dollar
          end{equation}


          begin{equation}
          tcbhighmath[title=short-title]{lambda=at^2+bt^3}%<---- without a double dollar
          end{equation}
          end{document}


          A fix for avoiding the $ characters in the main argument:



          documentclass[11pt]{article}
          usepackage{array}
          usepackage[many]{tcolorbox}

          tcbset{longtitle/.style={%
          title={#1},
          before upper={%
          $begin{array}{@{}>{displaystyle}l@{}}
          mbox{phantom{#1}}\[thedimexpr-htstrutbox-dpstrutbox]%
          },
          after upper={end{array}$}},
          }

          begin{document}

          begin{equation}
          tcbhighmath[longtitle=A long title hence does now fit]{lambda=at^2}
          end{equation}

          begin{equation}
          tcbhighmath[title=short-title]{lambda=at^2+bt^3}
          end{equation}

          end{document}





          share|improve this answer


























          • @egreg Thank you very much (Tks to infty) for your precious edit.

            – Sebastiano
            Jan 5 at 21:30














          10












          10








          10







          From this excellent macro of Thomas F. Sturm: ....fit the width...., here there is my adapt answer:



          enter image description here



          documentclass[11pt]{article}
          usepackage[many]{tcolorbox}
          tcbset{longtitle/.style={%
          title={#1},
          before upper={begin{tabular}{@{}l@{}l}phantom{#1}\[thedimexpr-htstrutbox-dpstrutbox]},
          after upper={end{tabular}}}
          }

          begin{document}
          begin{equation}
          tcbhighmath[longtitle=A long title hence does now fit]{$lambda=at^2$}%<---- for a double dollar
          end{equation}


          begin{equation}
          tcbhighmath[title=short-title]{lambda=at^2+bt^3}%<---- without a double dollar
          end{equation}
          end{document}


          A fix for avoiding the $ characters in the main argument:



          documentclass[11pt]{article}
          usepackage{array}
          usepackage[many]{tcolorbox}

          tcbset{longtitle/.style={%
          title={#1},
          before upper={%
          $begin{array}{@{}>{displaystyle}l@{}}
          mbox{phantom{#1}}\[thedimexpr-htstrutbox-dpstrutbox]%
          },
          after upper={end{array}$}},
          }

          begin{document}

          begin{equation}
          tcbhighmath[longtitle=A long title hence does now fit]{lambda=at^2}
          end{equation}

          begin{equation}
          tcbhighmath[title=short-title]{lambda=at^2+bt^3}
          end{equation}

          end{document}





          share|improve this answer















          From this excellent macro of Thomas F. Sturm: ....fit the width...., here there is my adapt answer:



          enter image description here



          documentclass[11pt]{article}
          usepackage[many]{tcolorbox}
          tcbset{longtitle/.style={%
          title={#1},
          before upper={begin{tabular}{@{}l@{}l}phantom{#1}\[thedimexpr-htstrutbox-dpstrutbox]},
          after upper={end{tabular}}}
          }

          begin{document}
          begin{equation}
          tcbhighmath[longtitle=A long title hence does now fit]{$lambda=at^2$}%<---- for a double dollar
          end{equation}


          begin{equation}
          tcbhighmath[title=short-title]{lambda=at^2+bt^3}%<---- without a double dollar
          end{equation}
          end{document}


          A fix for avoiding the $ characters in the main argument:



          documentclass[11pt]{article}
          usepackage{array}
          usepackage[many]{tcolorbox}

          tcbset{longtitle/.style={%
          title={#1},
          before upper={%
          $begin{array}{@{}>{displaystyle}l@{}}
          mbox{phantom{#1}}\[thedimexpr-htstrutbox-dpstrutbox]%
          },
          after upper={end{array}$}},
          }

          begin{document}

          begin{equation}
          tcbhighmath[longtitle=A long title hence does now fit]{lambda=at^2}
          end{equation}

          begin{equation}
          tcbhighmath[title=short-title]{lambda=at^2+bt^3}
          end{equation}

          end{document}






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Jan 5 at 21:26









          egreg

          728k8819233233




          728k8819233233










          answered Jan 5 at 21:16









          SebastianoSebastiano

          11.1k42164




          11.1k42164













          • @egreg Thank you very much (Tks to infty) for your precious edit.

            – Sebastiano
            Jan 5 at 21:30



















          • @egreg Thank you very much (Tks to infty) for your precious edit.

            – Sebastiano
            Jan 5 at 21:30

















          @egreg Thank you very much (Tks to infty) for your precious edit.

          – Sebastiano
          Jan 5 at 21:30





          @egreg Thank you very much (Tks to infty) for your precious edit.

          – Sebastiano
          Jan 5 at 21:30


















          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.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f468724%2fauto-width-tcolorbox-around-equation%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

          Bressuire

          Cabo Verde

          Gyllenstierna