Auto width tcolorbox around equation












6














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





























    6














    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



























      6












      6








      6


      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}

      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 yesterday

























      asked yesterday









      Ashok

      399211




      399211






















          2 Answers
          2






          active

          oldest

          votes


















          5














          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"}
          defwidth{pgfmathresult pt}
          tcbset{title=#1,
          tcbox width=minimum center,
          text width=width}}

          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
            yesterday



















          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}
          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
            yesterday











          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









          5














          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"}
          defwidth{pgfmathresult pt}
          tcbset{title=#1,
          tcbox width=minimum center,
          text width=width}}

          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
            yesterday
















          5














          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"}
          defwidth{pgfmathresult pt}
          tcbset{title=#1,
          tcbox width=minimum center,
          text width=width}}

          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
            yesterday














          5












          5








          5






          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"}
          defwidth{pgfmathresult pt}
          tcbset{title=#1,
          tcbox width=minimum center,
          text width=width}}

          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 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"}
          defwidth{pgfmathresult pt}
          tcbset{title=#1,
          tcbox width=minimum center,
          text width=width}}

          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 yesterday

























          answered yesterday









          Hafid Boukhoulda

          2,0321517




          2,0321517








          • 1




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














          • 1




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








          1




          1




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




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











          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}
          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
            yesterday
















          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}
          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
            yesterday














          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}
          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 yesterday









          egreg

          710k8618873171




          710k8618873171










          answered yesterday









          Sebastiano

          9,23841756




          9,23841756












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


















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
















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




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


















          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%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

          An IMO inspired problem

          Management

          Has there ever been an instance of an active nuclear power plant within or near a war zone?