%%
%% Copyright (c) 2022-2024 by Friedemann Bartels
%%
%% This file may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either
%% version 1.3c of this license or (at your option) any later
%% version.  The latest version of this license is in:
%%
%%    http://www.latex-project.org/lppl.txt
%%
%% and version 1.3c or later is part of all distributions of
%% LaTeX version 2008/05/04 or later.
%%

\documentclass{pagelayout}
\usepackage{lipsum}

\pagewidth=20cm
\pageheight=20cm
\gutter=10mm

\grid

\begin{document}

  \page{
    \setgrid{
      {{1}{1}}
      {{1}{1}}
    }

    \text{
      A grid with two rows and two cells in each row.
    }
  }

  \page{
    \setgrid{
      {{3}{2}}
      {{2}{3}}
    }

    \text{
      A grid with a width relation between cells.
    }
  }

  \page{
    \setgrid{
      {[3]{1}{1}}
      {[1]{1}{1}}
    }

    \text{
      A grid with a height relation between rows.
    }
  }

  \page{
    \setgrid{
      {[2]{1}{3!}}
      {[2]{1}{2!}}
    }

    \text{
      A grid with a fixed aspect ratio of some cells.
    }

    \graphic{3x2}

    \place{1 1 2 2}
    \graphic{1x1}
  }

  \page{
    \setgrid{
      {[1]{1!}{1!}{1!}}
      {[2]{4!}{3!}}
    }

    \text{
      A grid with a fixed aspect ratio of all cells.
    }

    \place{0 0 1 1}
    \graphic{1x1}

    \graphic{1x1}

    \graphic{1x1}

    \graphic{2x1}

    \graphic{3x2}
  }

  \page{
    \setgrid{
      {[2]{2!}{2!}{2!}}
      {[2!]{4!}{3}}
    }

    \graphic{1x1}

    \graphic{1x1}

    \graphic{1x1}

    \graphic{2x1}

    \text{
      A grid with a fixed height relation between rows.
    }
  }

  \page[gutter=10mm]{
    \setgrid[
      width=0.5\width,
      x=\margin
    ]{
      {{1}}
    }
    \text{
      Multiple grids on one page.
    }
    \setgrid[
      width=0.5\width-\gutter,
      x=\margin+0.5\width+\gutter
    ]{
      {{1}}
      {{1}}
      {{1}}
    }
  }

  \page{
    \setgrid[width=\height]{
      {{1}{1}}
      {{1}{1}}
    }
    \text{
      A grid with free positioned content. The gutter is preserved.
    }
    \place{0.5 0.5 1.5 1.5}
    \graphic{1x1}
    \place{1.5 1.5 2 2}
    \graphic{1x1}
  }

\end{document}
