How to retrieve the height of the box in a beamercolorbox environment?
I am working at a new beamer theme and I am wondering if it is possible to retrieve the height of the last shipped out beamercolorbox
. To set up a reasonable minimal (although horribly looking) working example, let us focus on the frametitle
template and let us assume (like it is in many themes) that the frame title is basically put into a beamercolorbox
.
documentclass{beamer}
usetheme{Madrid}
makeatletter
defbeamertemplate*{frametitle}{myFrametitle}[1][left]
{
begin{beamercolorbox}[sep=0.3cm,wd=textwidth]{frametitle}
usebeamerfont{frametitle}%
strutinsertframetitlestrutpar%
{%
ifxinsertframesubtitle@empty%
else%
{usebeamerfont{framesubtitle}usebeamercolor[fg]{framesubtitle}insertframesubtitlestrutpar}%
fi
}%
end{beamercolorbox}%
%-----
% Here I would like to have a length with the height of the
% above beamercolorbox, to be used to adapt dynamically stuff
%-----
}
makeatother
setbeamertemplate{frametitle}[myFrametitle]
begin{document}
begin{frame}{Frame title}
A frame
end{frame}
begin{frame}{Frame title}{with subtitle}
Another frame
end{frame}
end{document}
Is there an elegant way to retrieve the height of the box in the last beamercolorbox
environment?
More information
Reading the
beamerbasecolor.sty
file, I thought that I might redefine thebeamercolorbox
environment adding a line like
globalsetlength{@lastbeamercolorboxheight}{htbeamer@tempbox}%
before each
boxbeamer@tempbox%
, where@lastbeamercolorboxheight
would be an internal length of my theme. However, I do not like the idea of copying tons of beamer code just for a minimal add-on and, moreover, it does not look neither so elegant nor the way to go (see below to have a concrete example of this approach).
I am aware that I might use the
ht
anddp
keys of thebeamercolorbox
to fix the height of the box, but this is not a valid approach in my case. It is more like, the user puts whatever she/he want in the frame title/subtitle and I act dynamically accordingly.I am glad to receive any general hint and possibly slightly different approaches are welcome.
If the elegant solution is not to use a
beamercolorbox
at all, well, I will then think to an alternative from a more general perspective.
Redefining the beamercolorbox
environment
Although this is not an elegant way to retrieve the height of the box, it gives access to the desired length. However, there are probably many drawbacks, but the code here might help readers suggesting better approaches.
documentclass{beamer}
usetheme{Madrid}
makeatletter
newlength{@lastbeamercolorboxheight}
renewenvironment{beamercolorbox}[2]{% taken from beamerbasecolor.sty
begingroup%
defbeamer@colbox@coladd{0pt}%
defbeamer@vmode{leavevmode}%
setkeys{beamercolbox}{%
wd=textwidth,ht={},dp={},%
leftskip=0pt,rightskip=0pt plus1fil,%
sep=0pt,colsep=0pt,colsep*=0pt,%
shadow=false,rounded=false,ignorebg=false}%
setkeys{beamercolbox}{#1}%
ifbeamercolorempty[bg]{#2}{@tempswafalse}{@tempswatrue}%
ifbeamer@colbox@ignorebg@tempswafalsefi%
defbeamer@colbox@color{#2}%
hsize=beamer@colbox@wd%
setboxbeamer@tempbox=hboxbgroupvboxbgroup%
leftskip=beamer@colbox@ls%
advanceleftskip bybeamer@colbox@sep%
rightskip=beamer@colbox@rs%
advancerightskip bybeamer@colbox@sep%
ifbeamer@colbox@ignorebg%
colorlet{beamer@temp@color}{bg}%
usebeamercolor[fg]{#2}%
colorlet{bg}{beamer@temp@color}%
else%
usebeamercolor[fg]{#2}%
fi%
if@tempswa%
advanceleftskip bybeamer@colbox@colsep%
advancerightskip bybeamer@colbox@colsep%
ifdimbeamer@colbox@colsep=0ptelsevskipbeamer@colbox@colsepfi%
ifdimbeamer@colbox@colseps=0ptelsevskipbeamer@colbox@colsepsfi%
fi%
ifdimbeamer@colbox@sep=0ptelsevskipbeamer@colbox@sepfi%
beamer@vmodeignorespaces}{%
ifdimbeamer@colbox@sep=0ptelsevskipbeamer@colbox@sepfi%
if@tempswaifdimbeamer@colbox@colsep=0ptelsevskipbeamer@colbox@colsepfifi%
if@tempswaifdimbeamer@colbox@colseps=0ptelsevskipbeamer@colbox@colsepsfifi%
egroupegroup%
wdbeamer@tempbox=hsize%
@tempdima=wdbeamer@tempbox%
ifxbeamer@colbox@ht@empty%
else%
htbeamer@tempbox=beamer@colbox@ht%
fi%
ifxbeamer@colbox@dp@empty%
else%
dpbeamer@tempbox=beamer@colbox@dp%
fi%
ifbeamer@colbox@rounded%
if@tempswa%
begin{beamerboxesrounded}[%
shadow=beamer@colbox@shadow,%
lower=beamer@colbox@color,%
upper=normal text,%
width=beamer@colbox@wd]{}%
globalsetlength{@lastbeamercolorboxheight}{htbeamer@tempbox}% <--- ADDED
boxbeamer@tempbox%
end{beamerboxesrounded}%
else%
ifdim@tempdima>textwidth%
setboxbeamer@tempbox=hbox totextwidth{hssboxbeamer@tempboxhss}%
fi%
globalsetlength{@lastbeamercolorboxheight}{htbeamer@tempbox}% <--- ADDED
boxbeamer@tempbox%
fi%
else%
if@tempswasetboxbeamer@tempbox=hbox{vbox{%
usebeamercolor{beamer@colbox@color}%
advancehsize by beamer@colbox@colsepsrelax%
advancehsize by beamer@colbox@colsepsrelax%
hskip-beamer@colbox@colseps%
fboxsep=0ptcolorbox{bg}{%
hskipbeamer@colbox@colseps%
hbox{boxbeamer@tempbox}%
hskipbeamer@colbox@colseps%
}%
hskip-beamer@colbox@colseps%
}}fi%
ifdim@tempdima>textwidth%
setboxbeamer@tempbox=hbox totextwidth{hskip0pt minusbeamer@leftmarginrelaxboxbeamer@tempboxhskip0pt minusbeamer@rightmarginrelax}%
fi%
globalsetlength{@lastbeamercolorboxheight}{htbeamer@tempbox}% <--- ADDED
boxbeamer@tempbox%
fi%
endgroup%
}
defbeamertemplate*{frametitle}{myFrametitle}
{
begin{beamercolorbox}[sep=0.3cm,wd=textwidth]{frametitle}
usebeamerfont{frametitle}%
strutinsertframetitlestrutpar%
{%
ifxinsertframesubtitle@empty%
else%
{usebeamerfont{framesubtitle}usebeamercolor[fg]{framesubtitle}insertframesubtitlestrutpar}%
fi
}%
end{beamercolorbox}%
%-----
% Here the length @lastbeamercolorboxheight is set to the height of the box above
textcolor{black}{the@lastbeamercolorboxheight}
}
makeatother
setbeamertemplate{frametitle}[myFrametitle]
begin{document}
begin{frame}{Frame title}
A frame
end{frame}
begin{frame}{Frame title}{with subtitle}
Another frame
end{frame}
end{document}
And the result is the following.
beamer
add a comment |
I am working at a new beamer theme and I am wondering if it is possible to retrieve the height of the last shipped out beamercolorbox
. To set up a reasonable minimal (although horribly looking) working example, let us focus on the frametitle
template and let us assume (like it is in many themes) that the frame title is basically put into a beamercolorbox
.
documentclass{beamer}
usetheme{Madrid}
makeatletter
defbeamertemplate*{frametitle}{myFrametitle}[1][left]
{
begin{beamercolorbox}[sep=0.3cm,wd=textwidth]{frametitle}
usebeamerfont{frametitle}%
strutinsertframetitlestrutpar%
{%
ifxinsertframesubtitle@empty%
else%
{usebeamerfont{framesubtitle}usebeamercolor[fg]{framesubtitle}insertframesubtitlestrutpar}%
fi
}%
end{beamercolorbox}%
%-----
% Here I would like to have a length with the height of the
% above beamercolorbox, to be used to adapt dynamically stuff
%-----
}
makeatother
setbeamertemplate{frametitle}[myFrametitle]
begin{document}
begin{frame}{Frame title}
A frame
end{frame}
begin{frame}{Frame title}{with subtitle}
Another frame
end{frame}
end{document}
Is there an elegant way to retrieve the height of the box in the last beamercolorbox
environment?
More information
Reading the
beamerbasecolor.sty
file, I thought that I might redefine thebeamercolorbox
environment adding a line like
globalsetlength{@lastbeamercolorboxheight}{htbeamer@tempbox}%
before each
boxbeamer@tempbox%
, where@lastbeamercolorboxheight
would be an internal length of my theme. However, I do not like the idea of copying tons of beamer code just for a minimal add-on and, moreover, it does not look neither so elegant nor the way to go (see below to have a concrete example of this approach).
I am aware that I might use the
ht
anddp
keys of thebeamercolorbox
to fix the height of the box, but this is not a valid approach in my case. It is more like, the user puts whatever she/he want in the frame title/subtitle and I act dynamically accordingly.I am glad to receive any general hint and possibly slightly different approaches are welcome.
If the elegant solution is not to use a
beamercolorbox
at all, well, I will then think to an alternative from a more general perspective.
Redefining the beamercolorbox
environment
Although this is not an elegant way to retrieve the height of the box, it gives access to the desired length. However, there are probably many drawbacks, but the code here might help readers suggesting better approaches.
documentclass{beamer}
usetheme{Madrid}
makeatletter
newlength{@lastbeamercolorboxheight}
renewenvironment{beamercolorbox}[2]{% taken from beamerbasecolor.sty
begingroup%
defbeamer@colbox@coladd{0pt}%
defbeamer@vmode{leavevmode}%
setkeys{beamercolbox}{%
wd=textwidth,ht={},dp={},%
leftskip=0pt,rightskip=0pt plus1fil,%
sep=0pt,colsep=0pt,colsep*=0pt,%
shadow=false,rounded=false,ignorebg=false}%
setkeys{beamercolbox}{#1}%
ifbeamercolorempty[bg]{#2}{@tempswafalse}{@tempswatrue}%
ifbeamer@colbox@ignorebg@tempswafalsefi%
defbeamer@colbox@color{#2}%
hsize=beamer@colbox@wd%
setboxbeamer@tempbox=hboxbgroupvboxbgroup%
leftskip=beamer@colbox@ls%
advanceleftskip bybeamer@colbox@sep%
rightskip=beamer@colbox@rs%
advancerightskip bybeamer@colbox@sep%
ifbeamer@colbox@ignorebg%
colorlet{beamer@temp@color}{bg}%
usebeamercolor[fg]{#2}%
colorlet{bg}{beamer@temp@color}%
else%
usebeamercolor[fg]{#2}%
fi%
if@tempswa%
advanceleftskip bybeamer@colbox@colsep%
advancerightskip bybeamer@colbox@colsep%
ifdimbeamer@colbox@colsep=0ptelsevskipbeamer@colbox@colsepfi%
ifdimbeamer@colbox@colseps=0ptelsevskipbeamer@colbox@colsepsfi%
fi%
ifdimbeamer@colbox@sep=0ptelsevskipbeamer@colbox@sepfi%
beamer@vmodeignorespaces}{%
ifdimbeamer@colbox@sep=0ptelsevskipbeamer@colbox@sepfi%
if@tempswaifdimbeamer@colbox@colsep=0ptelsevskipbeamer@colbox@colsepfifi%
if@tempswaifdimbeamer@colbox@colseps=0ptelsevskipbeamer@colbox@colsepsfifi%
egroupegroup%
wdbeamer@tempbox=hsize%
@tempdima=wdbeamer@tempbox%
ifxbeamer@colbox@ht@empty%
else%
htbeamer@tempbox=beamer@colbox@ht%
fi%
ifxbeamer@colbox@dp@empty%
else%
dpbeamer@tempbox=beamer@colbox@dp%
fi%
ifbeamer@colbox@rounded%
if@tempswa%
begin{beamerboxesrounded}[%
shadow=beamer@colbox@shadow,%
lower=beamer@colbox@color,%
upper=normal text,%
width=beamer@colbox@wd]{}%
globalsetlength{@lastbeamercolorboxheight}{htbeamer@tempbox}% <--- ADDED
boxbeamer@tempbox%
end{beamerboxesrounded}%
else%
ifdim@tempdima>textwidth%
setboxbeamer@tempbox=hbox totextwidth{hssboxbeamer@tempboxhss}%
fi%
globalsetlength{@lastbeamercolorboxheight}{htbeamer@tempbox}% <--- ADDED
boxbeamer@tempbox%
fi%
else%
if@tempswasetboxbeamer@tempbox=hbox{vbox{%
usebeamercolor{beamer@colbox@color}%
advancehsize by beamer@colbox@colsepsrelax%
advancehsize by beamer@colbox@colsepsrelax%
hskip-beamer@colbox@colseps%
fboxsep=0ptcolorbox{bg}{%
hskipbeamer@colbox@colseps%
hbox{boxbeamer@tempbox}%
hskipbeamer@colbox@colseps%
}%
hskip-beamer@colbox@colseps%
}}fi%
ifdim@tempdima>textwidth%
setboxbeamer@tempbox=hbox totextwidth{hskip0pt minusbeamer@leftmarginrelaxboxbeamer@tempboxhskip0pt minusbeamer@rightmarginrelax}%
fi%
globalsetlength{@lastbeamercolorboxheight}{htbeamer@tempbox}% <--- ADDED
boxbeamer@tempbox%
fi%
endgroup%
}
defbeamertemplate*{frametitle}{myFrametitle}
{
begin{beamercolorbox}[sep=0.3cm,wd=textwidth]{frametitle}
usebeamerfont{frametitle}%
strutinsertframetitlestrutpar%
{%
ifxinsertframesubtitle@empty%
else%
{usebeamerfont{framesubtitle}usebeamercolor[fg]{framesubtitle}insertframesubtitlestrutpar}%
fi
}%
end{beamercolorbox}%
%-----
% Here the length @lastbeamercolorboxheight is set to the height of the box above
textcolor{black}{the@lastbeamercolorboxheight}
}
makeatother
setbeamertemplate{frametitle}[myFrametitle]
begin{document}
begin{frame}{Frame title}
A frame
end{frame}
begin{frame}{Frame title}{with subtitle}
Another frame
end{frame}
end{document}
And the result is the following.
beamer
IIRC, beamer doesn't add the frame title or compute the height of the colorbox until after everything else is done. The information simply isn't available when you want it.
– John Kormylo
Feb 15 at 16:17
See also tex.stackexchange.com/questions/397523/tikz-based-beamer-frame/…
– John Kormylo
Feb 15 at 16:33
@JohnKormylo I am not sure. If I define a new length and I set it in a redefinition of thebeamercolorbox
environment as I wrote in the first bullet above, I can use it after the environment. If you mean that I should compile twice the document to really have it available, well, this is completely fine for me.
– Axel Krypton
Feb 15 at 16:37
@JohnKormylo I edited the question setting up a second MWE in which I did explicitly what I meant in the work-around proposed in the question. Maybe you were thinking to something else respect to what I meant. Sorry if I was unclear. I hope this add-on clarifies more.
– Axel Krypton
Feb 15 at 17:08
add a comment |
I am working at a new beamer theme and I am wondering if it is possible to retrieve the height of the last shipped out beamercolorbox
. To set up a reasonable minimal (although horribly looking) working example, let us focus on the frametitle
template and let us assume (like it is in many themes) that the frame title is basically put into a beamercolorbox
.
documentclass{beamer}
usetheme{Madrid}
makeatletter
defbeamertemplate*{frametitle}{myFrametitle}[1][left]
{
begin{beamercolorbox}[sep=0.3cm,wd=textwidth]{frametitle}
usebeamerfont{frametitle}%
strutinsertframetitlestrutpar%
{%
ifxinsertframesubtitle@empty%
else%
{usebeamerfont{framesubtitle}usebeamercolor[fg]{framesubtitle}insertframesubtitlestrutpar}%
fi
}%
end{beamercolorbox}%
%-----
% Here I would like to have a length with the height of the
% above beamercolorbox, to be used to adapt dynamically stuff
%-----
}
makeatother
setbeamertemplate{frametitle}[myFrametitle]
begin{document}
begin{frame}{Frame title}
A frame
end{frame}
begin{frame}{Frame title}{with subtitle}
Another frame
end{frame}
end{document}
Is there an elegant way to retrieve the height of the box in the last beamercolorbox
environment?
More information
Reading the
beamerbasecolor.sty
file, I thought that I might redefine thebeamercolorbox
environment adding a line like
globalsetlength{@lastbeamercolorboxheight}{htbeamer@tempbox}%
before each
boxbeamer@tempbox%
, where@lastbeamercolorboxheight
would be an internal length of my theme. However, I do not like the idea of copying tons of beamer code just for a minimal add-on and, moreover, it does not look neither so elegant nor the way to go (see below to have a concrete example of this approach).
I am aware that I might use the
ht
anddp
keys of thebeamercolorbox
to fix the height of the box, but this is not a valid approach in my case. It is more like, the user puts whatever she/he want in the frame title/subtitle and I act dynamically accordingly.I am glad to receive any general hint and possibly slightly different approaches are welcome.
If the elegant solution is not to use a
beamercolorbox
at all, well, I will then think to an alternative from a more general perspective.
Redefining the beamercolorbox
environment
Although this is not an elegant way to retrieve the height of the box, it gives access to the desired length. However, there are probably many drawbacks, but the code here might help readers suggesting better approaches.
documentclass{beamer}
usetheme{Madrid}
makeatletter
newlength{@lastbeamercolorboxheight}
renewenvironment{beamercolorbox}[2]{% taken from beamerbasecolor.sty
begingroup%
defbeamer@colbox@coladd{0pt}%
defbeamer@vmode{leavevmode}%
setkeys{beamercolbox}{%
wd=textwidth,ht={},dp={},%
leftskip=0pt,rightskip=0pt plus1fil,%
sep=0pt,colsep=0pt,colsep*=0pt,%
shadow=false,rounded=false,ignorebg=false}%
setkeys{beamercolbox}{#1}%
ifbeamercolorempty[bg]{#2}{@tempswafalse}{@tempswatrue}%
ifbeamer@colbox@ignorebg@tempswafalsefi%
defbeamer@colbox@color{#2}%
hsize=beamer@colbox@wd%
setboxbeamer@tempbox=hboxbgroupvboxbgroup%
leftskip=beamer@colbox@ls%
advanceleftskip bybeamer@colbox@sep%
rightskip=beamer@colbox@rs%
advancerightskip bybeamer@colbox@sep%
ifbeamer@colbox@ignorebg%
colorlet{beamer@temp@color}{bg}%
usebeamercolor[fg]{#2}%
colorlet{bg}{beamer@temp@color}%
else%
usebeamercolor[fg]{#2}%
fi%
if@tempswa%
advanceleftskip bybeamer@colbox@colsep%
advancerightskip bybeamer@colbox@colsep%
ifdimbeamer@colbox@colsep=0ptelsevskipbeamer@colbox@colsepfi%
ifdimbeamer@colbox@colseps=0ptelsevskipbeamer@colbox@colsepsfi%
fi%
ifdimbeamer@colbox@sep=0ptelsevskipbeamer@colbox@sepfi%
beamer@vmodeignorespaces}{%
ifdimbeamer@colbox@sep=0ptelsevskipbeamer@colbox@sepfi%
if@tempswaifdimbeamer@colbox@colsep=0ptelsevskipbeamer@colbox@colsepfifi%
if@tempswaifdimbeamer@colbox@colseps=0ptelsevskipbeamer@colbox@colsepsfifi%
egroupegroup%
wdbeamer@tempbox=hsize%
@tempdima=wdbeamer@tempbox%
ifxbeamer@colbox@ht@empty%
else%
htbeamer@tempbox=beamer@colbox@ht%
fi%
ifxbeamer@colbox@dp@empty%
else%
dpbeamer@tempbox=beamer@colbox@dp%
fi%
ifbeamer@colbox@rounded%
if@tempswa%
begin{beamerboxesrounded}[%
shadow=beamer@colbox@shadow,%
lower=beamer@colbox@color,%
upper=normal text,%
width=beamer@colbox@wd]{}%
globalsetlength{@lastbeamercolorboxheight}{htbeamer@tempbox}% <--- ADDED
boxbeamer@tempbox%
end{beamerboxesrounded}%
else%
ifdim@tempdima>textwidth%
setboxbeamer@tempbox=hbox totextwidth{hssboxbeamer@tempboxhss}%
fi%
globalsetlength{@lastbeamercolorboxheight}{htbeamer@tempbox}% <--- ADDED
boxbeamer@tempbox%
fi%
else%
if@tempswasetboxbeamer@tempbox=hbox{vbox{%
usebeamercolor{beamer@colbox@color}%
advancehsize by beamer@colbox@colsepsrelax%
advancehsize by beamer@colbox@colsepsrelax%
hskip-beamer@colbox@colseps%
fboxsep=0ptcolorbox{bg}{%
hskipbeamer@colbox@colseps%
hbox{boxbeamer@tempbox}%
hskipbeamer@colbox@colseps%
}%
hskip-beamer@colbox@colseps%
}}fi%
ifdim@tempdima>textwidth%
setboxbeamer@tempbox=hbox totextwidth{hskip0pt minusbeamer@leftmarginrelaxboxbeamer@tempboxhskip0pt minusbeamer@rightmarginrelax}%
fi%
globalsetlength{@lastbeamercolorboxheight}{htbeamer@tempbox}% <--- ADDED
boxbeamer@tempbox%
fi%
endgroup%
}
defbeamertemplate*{frametitle}{myFrametitle}
{
begin{beamercolorbox}[sep=0.3cm,wd=textwidth]{frametitle}
usebeamerfont{frametitle}%
strutinsertframetitlestrutpar%
{%
ifxinsertframesubtitle@empty%
else%
{usebeamerfont{framesubtitle}usebeamercolor[fg]{framesubtitle}insertframesubtitlestrutpar}%
fi
}%
end{beamercolorbox}%
%-----
% Here the length @lastbeamercolorboxheight is set to the height of the box above
textcolor{black}{the@lastbeamercolorboxheight}
}
makeatother
setbeamertemplate{frametitle}[myFrametitle]
begin{document}
begin{frame}{Frame title}
A frame
end{frame}
begin{frame}{Frame title}{with subtitle}
Another frame
end{frame}
end{document}
And the result is the following.
beamer
I am working at a new beamer theme and I am wondering if it is possible to retrieve the height of the last shipped out beamercolorbox
. To set up a reasonable minimal (although horribly looking) working example, let us focus on the frametitle
template and let us assume (like it is in many themes) that the frame title is basically put into a beamercolorbox
.
documentclass{beamer}
usetheme{Madrid}
makeatletter
defbeamertemplate*{frametitle}{myFrametitle}[1][left]
{
begin{beamercolorbox}[sep=0.3cm,wd=textwidth]{frametitle}
usebeamerfont{frametitle}%
strutinsertframetitlestrutpar%
{%
ifxinsertframesubtitle@empty%
else%
{usebeamerfont{framesubtitle}usebeamercolor[fg]{framesubtitle}insertframesubtitlestrutpar}%
fi
}%
end{beamercolorbox}%
%-----
% Here I would like to have a length with the height of the
% above beamercolorbox, to be used to adapt dynamically stuff
%-----
}
makeatother
setbeamertemplate{frametitle}[myFrametitle]
begin{document}
begin{frame}{Frame title}
A frame
end{frame}
begin{frame}{Frame title}{with subtitle}
Another frame
end{frame}
end{document}
Is there an elegant way to retrieve the height of the box in the last beamercolorbox
environment?
More information
Reading the
beamerbasecolor.sty
file, I thought that I might redefine thebeamercolorbox
environment adding a line like
globalsetlength{@lastbeamercolorboxheight}{htbeamer@tempbox}%
before each
boxbeamer@tempbox%
, where@lastbeamercolorboxheight
would be an internal length of my theme. However, I do not like the idea of copying tons of beamer code just for a minimal add-on and, moreover, it does not look neither so elegant nor the way to go (see below to have a concrete example of this approach).
I am aware that I might use the
ht
anddp
keys of thebeamercolorbox
to fix the height of the box, but this is not a valid approach in my case. It is more like, the user puts whatever she/he want in the frame title/subtitle and I act dynamically accordingly.I am glad to receive any general hint and possibly slightly different approaches are welcome.
If the elegant solution is not to use a
beamercolorbox
at all, well, I will then think to an alternative from a more general perspective.
Redefining the beamercolorbox
environment
Although this is not an elegant way to retrieve the height of the box, it gives access to the desired length. However, there are probably many drawbacks, but the code here might help readers suggesting better approaches.
documentclass{beamer}
usetheme{Madrid}
makeatletter
newlength{@lastbeamercolorboxheight}
renewenvironment{beamercolorbox}[2]{% taken from beamerbasecolor.sty
begingroup%
defbeamer@colbox@coladd{0pt}%
defbeamer@vmode{leavevmode}%
setkeys{beamercolbox}{%
wd=textwidth,ht={},dp={},%
leftskip=0pt,rightskip=0pt plus1fil,%
sep=0pt,colsep=0pt,colsep*=0pt,%
shadow=false,rounded=false,ignorebg=false}%
setkeys{beamercolbox}{#1}%
ifbeamercolorempty[bg]{#2}{@tempswafalse}{@tempswatrue}%
ifbeamer@colbox@ignorebg@tempswafalsefi%
defbeamer@colbox@color{#2}%
hsize=beamer@colbox@wd%
setboxbeamer@tempbox=hboxbgroupvboxbgroup%
leftskip=beamer@colbox@ls%
advanceleftskip bybeamer@colbox@sep%
rightskip=beamer@colbox@rs%
advancerightskip bybeamer@colbox@sep%
ifbeamer@colbox@ignorebg%
colorlet{beamer@temp@color}{bg}%
usebeamercolor[fg]{#2}%
colorlet{bg}{beamer@temp@color}%
else%
usebeamercolor[fg]{#2}%
fi%
if@tempswa%
advanceleftskip bybeamer@colbox@colsep%
advancerightskip bybeamer@colbox@colsep%
ifdimbeamer@colbox@colsep=0ptelsevskipbeamer@colbox@colsepfi%
ifdimbeamer@colbox@colseps=0ptelsevskipbeamer@colbox@colsepsfi%
fi%
ifdimbeamer@colbox@sep=0ptelsevskipbeamer@colbox@sepfi%
beamer@vmodeignorespaces}{%
ifdimbeamer@colbox@sep=0ptelsevskipbeamer@colbox@sepfi%
if@tempswaifdimbeamer@colbox@colsep=0ptelsevskipbeamer@colbox@colsepfifi%
if@tempswaifdimbeamer@colbox@colseps=0ptelsevskipbeamer@colbox@colsepsfifi%
egroupegroup%
wdbeamer@tempbox=hsize%
@tempdima=wdbeamer@tempbox%
ifxbeamer@colbox@ht@empty%
else%
htbeamer@tempbox=beamer@colbox@ht%
fi%
ifxbeamer@colbox@dp@empty%
else%
dpbeamer@tempbox=beamer@colbox@dp%
fi%
ifbeamer@colbox@rounded%
if@tempswa%
begin{beamerboxesrounded}[%
shadow=beamer@colbox@shadow,%
lower=beamer@colbox@color,%
upper=normal text,%
width=beamer@colbox@wd]{}%
globalsetlength{@lastbeamercolorboxheight}{htbeamer@tempbox}% <--- ADDED
boxbeamer@tempbox%
end{beamerboxesrounded}%
else%
ifdim@tempdima>textwidth%
setboxbeamer@tempbox=hbox totextwidth{hssboxbeamer@tempboxhss}%
fi%
globalsetlength{@lastbeamercolorboxheight}{htbeamer@tempbox}% <--- ADDED
boxbeamer@tempbox%
fi%
else%
if@tempswasetboxbeamer@tempbox=hbox{vbox{%
usebeamercolor{beamer@colbox@color}%
advancehsize by beamer@colbox@colsepsrelax%
advancehsize by beamer@colbox@colsepsrelax%
hskip-beamer@colbox@colseps%
fboxsep=0ptcolorbox{bg}{%
hskipbeamer@colbox@colseps%
hbox{boxbeamer@tempbox}%
hskipbeamer@colbox@colseps%
}%
hskip-beamer@colbox@colseps%
}}fi%
ifdim@tempdima>textwidth%
setboxbeamer@tempbox=hbox totextwidth{hskip0pt minusbeamer@leftmarginrelaxboxbeamer@tempboxhskip0pt minusbeamer@rightmarginrelax}%
fi%
globalsetlength{@lastbeamercolorboxheight}{htbeamer@tempbox}% <--- ADDED
boxbeamer@tempbox%
fi%
endgroup%
}
defbeamertemplate*{frametitle}{myFrametitle}
{
begin{beamercolorbox}[sep=0.3cm,wd=textwidth]{frametitle}
usebeamerfont{frametitle}%
strutinsertframetitlestrutpar%
{%
ifxinsertframesubtitle@empty%
else%
{usebeamerfont{framesubtitle}usebeamercolor[fg]{framesubtitle}insertframesubtitlestrutpar}%
fi
}%
end{beamercolorbox}%
%-----
% Here the length @lastbeamercolorboxheight is set to the height of the box above
textcolor{black}{the@lastbeamercolorboxheight}
}
makeatother
setbeamertemplate{frametitle}[myFrametitle]
begin{document}
begin{frame}{Frame title}
A frame
end{frame}
begin{frame}{Frame title}{with subtitle}
Another frame
end{frame}
end{document}
And the result is the following.
beamer
beamer
edited Feb 15 at 17:06
Axel Krypton
asked Feb 15 at 16:00
Axel KryptonAxel Krypton
406110
406110
IIRC, beamer doesn't add the frame title or compute the height of the colorbox until after everything else is done. The information simply isn't available when you want it.
– John Kormylo
Feb 15 at 16:17
See also tex.stackexchange.com/questions/397523/tikz-based-beamer-frame/…
– John Kormylo
Feb 15 at 16:33
@JohnKormylo I am not sure. If I define a new length and I set it in a redefinition of thebeamercolorbox
environment as I wrote in the first bullet above, I can use it after the environment. If you mean that I should compile twice the document to really have it available, well, this is completely fine for me.
– Axel Krypton
Feb 15 at 16:37
@JohnKormylo I edited the question setting up a second MWE in which I did explicitly what I meant in the work-around proposed in the question. Maybe you were thinking to something else respect to what I meant. Sorry if I was unclear. I hope this add-on clarifies more.
– Axel Krypton
Feb 15 at 17:08
add a comment |
IIRC, beamer doesn't add the frame title or compute the height of the colorbox until after everything else is done. The information simply isn't available when you want it.
– John Kormylo
Feb 15 at 16:17
See also tex.stackexchange.com/questions/397523/tikz-based-beamer-frame/…
– John Kormylo
Feb 15 at 16:33
@JohnKormylo I am not sure. If I define a new length and I set it in a redefinition of thebeamercolorbox
environment as I wrote in the first bullet above, I can use it after the environment. If you mean that I should compile twice the document to really have it available, well, this is completely fine for me.
– Axel Krypton
Feb 15 at 16:37
@JohnKormylo I edited the question setting up a second MWE in which I did explicitly what I meant in the work-around proposed in the question. Maybe you were thinking to something else respect to what I meant. Sorry if I was unclear. I hope this add-on clarifies more.
– Axel Krypton
Feb 15 at 17:08
IIRC, beamer doesn't add the frame title or compute the height of the colorbox until after everything else is done. The information simply isn't available when you want it.
– John Kormylo
Feb 15 at 16:17
IIRC, beamer doesn't add the frame title or compute the height of the colorbox until after everything else is done. The information simply isn't available when you want it.
– John Kormylo
Feb 15 at 16:17
See also tex.stackexchange.com/questions/397523/tikz-based-beamer-frame/…
– John Kormylo
Feb 15 at 16:33
See also tex.stackexchange.com/questions/397523/tikz-based-beamer-frame/…
– John Kormylo
Feb 15 at 16:33
@JohnKormylo I am not sure. If I define a new length and I set it in a redefinition of the
beamercolorbox
environment as I wrote in the first bullet above, I can use it after the environment. If you mean that I should compile twice the document to really have it available, well, this is completely fine for me.– Axel Krypton
Feb 15 at 16:37
@JohnKormylo I am not sure. If I define a new length and I set it in a redefinition of the
beamercolorbox
environment as I wrote in the first bullet above, I can use it after the environment. If you mean that I should compile twice the document to really have it available, well, this is completely fine for me.– Axel Krypton
Feb 15 at 16:37
@JohnKormylo I edited the question setting up a second MWE in which I did explicitly what I meant in the work-around proposed in the question. Maybe you were thinking to something else respect to what I meant. Sorry if I was unclear. I hope this add-on clarifies more.
– Axel Krypton
Feb 15 at 17:08
@JohnKormylo I edited the question setting up a second MWE in which I did explicitly what I meant in the work-around proposed in the question. Maybe you were thinking to something else respect to what I meant. Sorry if I was unclear. I hope this add-on clarifies more.
– Axel Krypton
Feb 15 at 17:08
add a comment |
0
active
oldest
votes
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%2f475050%2fhow-to-retrieve-the-height-of-the-box-in-a-beamercolorbox-environment%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
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%2f475050%2fhow-to-retrieve-the-height-of-the-box-in-a-beamercolorbox-environment%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
IIRC, beamer doesn't add the frame title or compute the height of the colorbox until after everything else is done. The information simply isn't available when you want it.
– John Kormylo
Feb 15 at 16:17
See also tex.stackexchange.com/questions/397523/tikz-based-beamer-frame/…
– John Kormylo
Feb 15 at 16:33
@JohnKormylo I am not sure. If I define a new length and I set it in a redefinition of the
beamercolorbox
environment as I wrote in the first bullet above, I can use it after the environment. If you mean that I should compile twice the document to really have it available, well, this is completely fine for me.– Axel Krypton
Feb 15 at 16:37
@JohnKormylo I edited the question setting up a second MWE in which I did explicitly what I meant in the work-around proposed in the question. Maybe you were thinking to something else respect to what I meant. Sorry if I was unclear. I hope this add-on clarifies more.
– Axel Krypton
Feb 15 at 17:08