  Using density-functional theory in the restricted-orientation approximation,
we analyse the liquid-crystal patterns and phase behaviour of a fluid of hard
rectangular particles confined in a two-dimensional square nanocavity of side
length $H$ composed of hard inner walls. Patterning in the cavity is governed
by surface-induced order, capillary and frustration effects, and depends on the
relative values of particle aspect ratio $\kappa\equiv L/\sigma$, with $L$ the
length and $\sigma$ the width of the rectangles ($L\ge\sigma$), and cavity size
$H$. Ordering may be very different from bulk ($H\to\infty$) behaviour when $H$
is a few times the particle length $L$ (nanocavity). Bulk and confinement
properties are obtained for the cases $\kappa=1$, 3 and 6. In the confined
fluid surface-induced frustration leads to four-fold symmetry breaking in all
phases (which become two-fold symmetric). Since no director distorsion can
arise in our model by construction, frustration in the director orientation is
relaxed by the creation of domain walls (where the director changes by
$90^{\circ}$); this configuration is necessary to stabilise periodic phases.
For $\kappa=1$ the crystal becomes stable with commensuration transitions
taking place as $H$ is varied. In the case $\kappa=3$ the commensuration
transitions involve columnar phases with different number of columns. Finally,
in the case $\kappa=6$, the high-density region of the phase diagram is
dominated by commensuration transitions between smectic structures; at lower
densities there is a symmetry-breaking isotropic $\to$ nematic transition
exhibiting non-monotonic behaviour with cavity size.
