Auto width tcolorbox around equation
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}
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
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}
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
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}
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
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}
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
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"}
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}
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}
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}
@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"}
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}
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"}
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}
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"}
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}
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}
edited Jan 5 at 22:40
answered Jan 5 at 21:52
Hafid BoukhouldaHafid Boukhoulda
2,1221517
2,1221517
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}
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}
@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}
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}
@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}
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}
From this excellent macro of Thomas F. Sturm: ....fit the width...., here there is my adapt answer:
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}
edited Jan 5 at 21:26
egreg
710k8618883172
710k8618883172
answered Jan 5 at 21:16
SebastianoSebastiano
9,27841756
9,27841756
@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.
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.
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