What is the preferred way of doing side-by-side content?

I have been working with different people on various documents and have primarily seen these two ways to present content side by side:

#grid(
  columns: (1fr, 1fr),
  [
    Here is some explanatory text.
  ],
  [
   Something else, maybe code or an image.
  ]
)

#columns(2)[
  Here is some explanatory text.
  #colbreak()
  Something else, maybe code or an image.
]

What are the advantages of these methods? Is one favoured over the others? Are there other methods to do this that may or may not be better?

2 Likes

The #grid variant allows you to specify the width of each cell (for example setting columns: (1fr,2fr) to get a 1:2 ratio). It also allows to span across multiple columns or rows (although could get pretty messy).

The #columns variant on the other hand strictly limits the content to equally sized columns, but allows you to switch to the other column at any time with #colbreak().

So, columns has more of a waterfall flow, which is great for writing texts, while grids use self contained cells (they don’t flow great with a paragraph).

2 Likes

The stack function is an alternative, simpler than grid, so it has less options than a grid.

See also the wrap-it package for wrapping content around a figure.

2 Likes

If it’s a main body content, then it’s definitely a column layout that is supported via

#set page(columns: 2)

Or locally with columns(2). The #set columns(gutter: 0pt) will affect both of them, so for local ones you should specify settings separately, if used with page.columns.

It also supports floating figures and stuff like that.

The rest depends on your use case. For grid-like layout use grid, for inline/one line spread use

Here is some explanatory text.#h(1fr)Something else, maybe code or an image.

Here is some explanatory text.#h(5em)Something else, maybe code or an image.

If grid is too much, maybe you can use stack:

#stack(dir: ltr, spacing: 1fr)[
  Here is some explanatory text.
][
  Something else, maybe code or an image.
]

#stack(
  dir: ltr,
  [
    Here is some explanatory text.
  ],
  h(1em),
  [
    Something else, maybe code or an image.
  ],
)
2 Likes