Auto width tcolorbox around equation

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












7















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

begindocument
beginequation
tcbhighmath[title=A long title hence does not fit]lambda=at^2
endequation

beginequation
tcbhighmath[title=short-title]lambda=at^2+bt^3
endequation
enddocument









share|improve this question




























    7















    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

    begindocument
    beginequation
    tcbhighmath[title=A long title hence does not fit]lambda=at^2
    endequation

    beginequation
    tcbhighmath[title=short-title]lambda=at^2+bt^3
    endequation
    enddocument









    share|improve this question


























      7












      7








      7


      1






      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

      begindocument
      beginequation
      tcbhighmath[title=A long title hence does not fit]lambda=at^2
      endequation

      beginequation
      tcbhighmath[title=short-title]lambda=at^2+bt^3
      endequation
      enddocument









      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

      begindocument
      beginequation
      tcbhighmath[title=A long title hence does not fit]lambda=at^2
      endequation

      beginequation
      tcbhighmath[title=short-title]lambda=at^2+bt^3
      endequation
      enddocument






      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

      404311




      404311




















          2 Answers
          2






          active

          oldest

          votes


















          6














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



          documentclass[11pt]article
          usepackage[many]tcolorbox
          pgfkeysdef/tcb/autowidth title
          pgfmathwidth"#1"
          defwidthpgfmathresult pt
          tcbsettitle=#1,
          tcbox width=minimum center,
          text width=width

          begindocument
          beginequation
          tcbhighmath[autowidth title=A long title hence does not fit ]lambda=at^2
          endequation

          beginequation
          tcbhighmath[autowidth title=short-title]lambda=at^2+bt^3
          endequation




          enddocument


          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


















          7














          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
          tcbsetlongtitle/.style=%
          title=#1,
          before upper=begintabular@l@lphantom#1\[thedimexpr-htstrutbox-dpstrutbox],
          after upper=endtabular


          begindocument
          beginequation
          tcbhighmath[longtitle=A long title hence does now fit]$lambda=at^2$%<---- for a double dollar
          endequation


          beginequation
          tcbhighmath[title=short-title]lambda=at^2+bt^3%<---- without a double dollar
          endequation
          enddocument


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



          documentclass[11pt]article
          usepackagearray
          usepackage[many]tcolorbox

          tcbsetlongtitle/.style=%
          title=#1,
          before upper=%
          $beginarray@>displaystylel@
          mboxphantom#1\[thedimexpr-htstrutbox-dpstrutbox]%
          ,
          after upper=endarray$,


          begindocument

          beginequation
          tcbhighmath[longtitle=A long title hence does now fit]lambda=at^2
          endequation

          beginequation
          tcbhighmath[title=short-title]lambda=at^2+bt^3
          endequation

          enddocument





          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









          6














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



          documentclass[11pt]article
          usepackage[many]tcolorbox
          pgfkeysdef/tcb/autowidth title
          pgfmathwidth"#1"
          defwidthpgfmathresult pt
          tcbsettitle=#1,
          tcbox width=minimum center,
          text width=width

          begindocument
          beginequation
          tcbhighmath[autowidth title=A long title hence does not fit ]lambda=at^2
          endequation

          beginequation
          tcbhighmath[autowidth title=short-title]lambda=at^2+bt^3
          endequation




          enddocument


          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















          6














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



          documentclass[11pt]article
          usepackage[many]tcolorbox
          pgfkeysdef/tcb/autowidth title
          pgfmathwidth"#1"
          defwidthpgfmathresult pt
          tcbsettitle=#1,
          tcbox width=minimum center,
          text width=width

          begindocument
          beginequation
          tcbhighmath[autowidth title=A long title hence does not fit ]lambda=at^2
          endequation

          beginequation
          tcbhighmath[autowidth title=short-title]lambda=at^2+bt^3
          endequation




          enddocument


          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













          6












          6








          6







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



          documentclass[11pt]article
          usepackage[many]tcolorbox
          pgfkeysdef/tcb/autowidth title
          pgfmathwidth"#1"
          defwidthpgfmathresult pt
          tcbsettitle=#1,
          tcbox width=minimum center,
          text width=width

          begindocument
          beginequation
          tcbhighmath[autowidth title=A long title hence does not fit ]lambda=at^2
          endequation

          beginequation
          tcbhighmath[autowidth title=short-title]lambda=at^2+bt^3
          endequation




          enddocument


          enter image description here






          share|improve this answer















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



          documentclass[11pt]article
          usepackage[many]tcolorbox
          pgfkeysdef/tcb/autowidth title
          pgfmathwidth"#1"
          defwidthpgfmathresult pt
          tcbsettitle=#1,
          tcbox width=minimum center,
          text width=width

          begindocument
          beginequation
          tcbhighmath[autowidth title=A long title hence does not fit ]lambda=at^2
          endequation

          beginequation
          tcbhighmath[autowidth title=short-title]lambda=at^2+bt^3
          endequation




          enddocument


          enter image description here







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Jan 5 at 22:40

























          answered Jan 5 at 21:52









          Hafid BoukhouldaHafid Boukhoulda

          2,2091517




          2,2091517







          • 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











          7














          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
          tcbsetlongtitle/.style=%
          title=#1,
          before upper=begintabular@l@lphantom#1\[thedimexpr-htstrutbox-dpstrutbox],
          after upper=endtabular


          begindocument
          beginequation
          tcbhighmath[longtitle=A long title hence does now fit]$lambda=at^2$%<---- for a double dollar
          endequation


          beginequation
          tcbhighmath[title=short-title]lambda=at^2+bt^3%<---- without a double dollar
          endequation
          enddocument


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



          documentclass[11pt]article
          usepackagearray
          usepackage[many]tcolorbox

          tcbsetlongtitle/.style=%
          title=#1,
          before upper=%
          $beginarray@>displaystylel@
          mboxphantom#1\[thedimexpr-htstrutbox-dpstrutbox]%
          ,
          after upper=endarray$,


          begindocument

          beginequation
          tcbhighmath[longtitle=A long title hence does now fit]lambda=at^2
          endequation

          beginequation
          tcbhighmath[title=short-title]lambda=at^2+bt^3
          endequation

          enddocument





          share|improve this answer

























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

            – Sebastiano
            Jan 5 at 21:30















          7














          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
          tcbsetlongtitle/.style=%
          title=#1,
          before upper=begintabular@l@lphantom#1\[thedimexpr-htstrutbox-dpstrutbox],
          after upper=endtabular


          begindocument
          beginequation
          tcbhighmath[longtitle=A long title hence does now fit]$lambda=at^2$%<---- for a double dollar
          endequation


          beginequation
          tcbhighmath[title=short-title]lambda=at^2+bt^3%<---- without a double dollar
          endequation
          enddocument


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



          documentclass[11pt]article
          usepackagearray
          usepackage[many]tcolorbox

          tcbsetlongtitle/.style=%
          title=#1,
          before upper=%
          $beginarray@>displaystylel@
          mboxphantom#1\[thedimexpr-htstrutbox-dpstrutbox]%
          ,
          after upper=endarray$,


          begindocument

          beginequation
          tcbhighmath[longtitle=A long title hence does now fit]lambda=at^2
          endequation

          beginequation
          tcbhighmath[title=short-title]lambda=at^2+bt^3
          endequation

          enddocument





          share|improve this answer

























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

            – Sebastiano
            Jan 5 at 21:30













          7












          7








          7







          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
          tcbsetlongtitle/.style=%
          title=#1,
          before upper=begintabular@l@lphantom#1\[thedimexpr-htstrutbox-dpstrutbox],
          after upper=endtabular


          begindocument
          beginequation
          tcbhighmath[longtitle=A long title hence does now fit]$lambda=at^2$%<---- for a double dollar
          endequation


          beginequation
          tcbhighmath[title=short-title]lambda=at^2+bt^3%<---- without a double dollar
          endequation
          enddocument


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



          documentclass[11pt]article
          usepackagearray
          usepackage[many]tcolorbox

          tcbsetlongtitle/.style=%
          title=#1,
          before upper=%
          $beginarray@>displaystylel@
          mboxphantom#1\[thedimexpr-htstrutbox-dpstrutbox]%
          ,
          after upper=endarray$,


          begindocument

          beginequation
          tcbhighmath[longtitle=A long title hence does now fit]lambda=at^2
          endequation

          beginequation
          tcbhighmath[title=short-title]lambda=at^2+bt^3
          endequation

          enddocument





          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
          tcbsetlongtitle/.style=%
          title=#1,
          before upper=begintabular@l@lphantom#1\[thedimexpr-htstrutbox-dpstrutbox],
          after upper=endtabular


          begindocument
          beginequation
          tcbhighmath[longtitle=A long title hence does now fit]$lambda=at^2$%<---- for a double dollar
          endequation


          beginequation
          tcbhighmath[title=short-title]lambda=at^2+bt^3%<---- without a double dollar
          endequation
          enddocument


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



          documentclass[11pt]article
          usepackagearray
          usepackage[many]tcolorbox

          tcbsetlongtitle/.style=%
          title=#1,
          before upper=%
          $beginarray@>displaystylel@
          mboxphantom#1\[thedimexpr-htstrutbox-dpstrutbox]%
          ,
          after upper=endarray$,


          begindocument

          beginequation
          tcbhighmath[longtitle=A long title hence does now fit]lambda=at^2
          endequation

          beginequation
          tcbhighmath[title=short-title]lambda=at^2+bt^3
          endequation

          enddocument






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Jan 5 at 21:26









          egreg

          713k8618953184




          713k8618953184










          answered Jan 5 at 21:16









          SebastianoSebastiano

          9,43441756




          9,43441756












          • @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

          Peggy Mitchell

          Palaiologos

          The Forum (Inglewood, California)