Section 19.3 <sidebyside>
One of the more complex pieces of code in PreTeXt, by most accounts, is that used for positioning objects (frequently
<image> and <tabular>, but also <p>) next to each other. If you’ve tried to do this in LaTeX, you know that it can be challenging on a good day. Fortunately, PreTeXt does the heavy lifting for us.
We include two examples here. The first places the
<sidebyside> directly in the current division and places a <figure> with a caption inside the <sidebyside>. The second puts the <sidebyside> inside <figure> and then uses an <image> not contained in a <figure> to include the graphic. It’s possible to do all sorts of nesting and get nice subnumbering automatically. More information on the capabilities of <sidebyside> can be found in Section 4.24.
<!--********************************************************************
Copyright (C) 2019-2026 Robert A. Beezer
This file is part of PreTeXt.
PreTeXt is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 or version 3 of the
License (at your option).
PreTeXt is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************-->
<sidebyside widths="25% 25%" valign="middle">
<figure>
<caption>Small graph with the caption only associated to the
image. </caption>
<image source="small-graph" />
</figure>
<p>
We can put a paragraph here.
Yes, a paragraph.
Isn't this the most exciting paragraph that you've ever seen?
It goes on and on and on and on and on and on.
We want to put enough here to make it wrap, really, is all.
Let's hope that this is enough.
</p>
</sidebyside>
The code in Listing 19.3.1 produces the following output:
We can put a paragraph here. Yes, a paragraph. Isn’t this the most exciting paragraph that you’ve ever seen? It goes on and on and on and on and on and on. We want to put enough here to make it wrap, really, is all. Let’s hope that this is enough.
<sidebyside><!--********************************************************************
Copyright (C) 2019-2026 Robert A. Beezer
This file is part of PreTeXt.
PreTeXt is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 or version 3 of the
License (at your option).
PreTeXt is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************-->
<figure>
<caption>A graphic next to a paragraph of
text with the caption assigned to both.</caption>
<sidebyside widths="25% 35%" margins="0% 0%"
valigns="bottom top">
<image source="small-graph" />
<p>
We can put a paragraph here.
Yes, a paragraph.
Isn't this the most exciting paragraph that you've ever seen?
It goes on and on and on and on and on and on.
We want to put enough here to make it wrap, really, is all.
Let's hope that this is enough.
</p>
</sidebyside>
</figure>
The code in Listing 19.3.3 produces the following output:
We can put a paragraph here. Yes, a paragraph. Isn’t this the most exciting paragraph that you’ve ever seen? It goes on and on and on and on and on and on. We want to put enough here to make it wrap, really, is all. Let’s hope that this is enough.
For a layout with multiple rows (but the same
@widths for each row, PreTeXt provides the side-by-side group using <sbsgroup>.
<sbsgroup><!--********************************************************************
Copyright (C) 2019-2026 Robert A. Beezer
This file is part of PreTeXt.
PreTeXt is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 or version 3 of the
License (at your option).
PreTeXt is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************-->
<sbsgroup widths="25% 50%" margins="5% 10%">
<sidebyside>
<image source="small-graph" />
<p>
A longer piece of text.
It goes on and on and on.
And on and on and on.
And eventually we will let it end,
but we want to show the width.
</p>
</sidebyside>
<sidebyside>
<p>
Another little snippet of text.
This time a bit longer so that it will wrap.
</p>
<p>
We're going to keep this paragraph shorter.
</p>
</sidebyside>
<sidebyside widths="75% 10%">
<p>Here is some text in a row where we have overridden the widths
specified above. Isn't this grand?</p>
<p>Super duper narrow. Look at me!</p>
</sidebyside>
</sbsgroup>
The code in Listing 19.3.5 produces the following output:
A longer piece of text. It goes on and on and on. And on and on and on. And eventually we will let it end, but we want to show the width.
Another little snippet of text. This time a bit longer so that it will wrap.
We’re going to keep this paragraph shorter.
Here is some text in a row where we have overridden the widths specified above. Isn’t this grand?
Super duper narrow. Look at me!
