Here's a receipe for drawing an image whose dimensions aren't known in advance on a background that scales to the image's final bounding box:
- Draw the image.
- Save the image in a picture variable.
- Measure the picture's bounding box.
- Draw the background.
- Re-draw the original image on top of the background.
Here's an example followed by some random notes:
beginfig(1);
%
% Draw random picture.
%
pair p,q;
for i = 1 upto 20:
p := (uniformdeviate 200, uniformdeviate 200);
q := (uniformdeviate 200, uniformdeviate 200);
draw p--q withpen pencircle scaled 2 withcolor red;
endfor
%
% Solution starts here.
%
% Save picture in variable pic for later reference.
picture pic;
pic := currentpicture;
% Clear currentpicture to avoid outputting the picture twice.
currentpicture := nullpicture;
% Fill a rectangle with pic's bounding box dimensions (plus
% bboxmargin) with desired background colour.
% interim bboxmargin := 0;
fill bbox pic withcolor blue;
% Draw original picture on top of background.
draw pic;
endfig;
end
Saving an image in a picture variable can either be done by storing currentpicture
in a picture variable or via the image
command (see the MetaPost manual for more information). If the currentpicture
method is used, like in the example, make sure to clear currentpicture
before drawing the background. Otherwise the image is output twice, the first copy being hidden behind the background, bloating the output file.
The bbox
command returns a rectangular path corresponding to the bounding box of the picture argument plus a small amount determined by the internal variable bboxmargin
(2bp by default).
Internal variables can be modified locally to the current group using the interim
statement. That is, if you wrap an assignment to an internal variable in begingroup ... endgroup;
the variable's value is restored after the group. Note, beginfig()
just starts a group that ends at the corresponding endfig
.
You can set the background color inside the \AtBeginSection
:
\AtBeginSection{
\begingroup
\setbeamercolor{background canvas}{bg=blue}
\frame{\sectionpage}
\endgroup
}
Then
\section{Content}
should give you a blue page.
Best Answer
Since you are not providing a MWE I'm using a standard sidebar theme to show what you need to do in principle. If you need something more specific for your use case please provide a MWE with your code.
You can customize the appearance as much as you like by styling the
TikZ
node.If you also want sections to be highlighted when there are subsections (by default Beamer shades a section when it has subsections), you need to add the following code to your preamble (kindly provided by @diabonas)