Skip to main content

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 , 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.16.

<sidebyside widths="25% 25%" valign="middle">
  <figure>
    <caption>Small graph with the caption only associated to the
    image. </caption>
    <image source="images/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>
Listing 19.3.1. Code to place things side by side

The code in Listing 19.3.1 produces the following output:

Figure 19.3.2. Small graph with the caption only associated to the image.

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.

<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="images/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>
Listing 19.3.3. A few more bells and whistles for <sidebyside>

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.

Figure 19.3.4. A graphic next to a paragraph of text with the caption assigned to both.

For a layout with multiple rows (but the same @widths for each row, PreTeXt provides the side-by-side group using <sbsgroup>.

<sbsgroup widths="25% 50%" margins="5% 10%">
    <sidebyside>
        <image source="images/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>
Listing 19.3.5. Use of <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!