Auto width tcolorbox around equation

Clash Royale CLAN TAG#URR8PPP
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:

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
add a comment |
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:

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
add a comment |
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:

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

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
equations tcolorbox width
edited Jan 5 at 16:44
Ashok
asked Jan 5 at 16:19
AshokAshok
404311
404311
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
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

1
My compliments for another answer. Very good and I have much appreciated it.
– Sebastiano
Jan 5 at 21:54
add a comment |
From this excellent macro of Thomas F. Sturm: ....fit the width...., here there is my adapt answer:

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
@egreg Thank you very much (Tks to infty) for your precious edit.
– Sebastiano
Jan 5 at 21:30
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%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
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

1
My compliments for another answer. Very good and I have much appreciated it.
– Sebastiano
Jan 5 at 21:54
add a comment |
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

1
My compliments for another answer. Very good and I have much appreciated it.
– Sebastiano
Jan 5 at 21:54
add a comment |
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

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

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
add a comment |
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
add a comment |
From this excellent macro of Thomas F. Sturm: ....fit the width...., here there is my adapt answer:

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
@egreg Thank you very much (Tks to infty) for your precious edit.
– Sebastiano
Jan 5 at 21:30
add a comment |
From this excellent macro of Thomas F. Sturm: ....fit the width...., here there is my adapt answer:

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
@egreg Thank you very much (Tks to infty) for your precious edit.
– Sebastiano
Jan 5 at 21:30
add a comment |
From this excellent macro of Thomas F. Sturm: ....fit the width...., here there is my adapt answer:

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
From this excellent macro of Thomas F. Sturm: ....fit the width...., here there is my adapt answer:

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
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
add a comment |
@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
add a comment |
Thanks for contributing an answer to TeX - LaTeX Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f468724%2fauto-width-tcolorbox-around-equation%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown