  By virtue of being atomically thin, the electronic properties of
heterostructures built from two-dimensional materials are strongly influenced
by atomic relaxation. The atomic layers behave as flexible membranes rather
than rigid crystals. Here we develop an analytical theory of lattice relaxation
in twisted moir\'e materials. We obtain analytical results for the lattice
displacements and corresponding pseudo gauge fields, as a function of twist
angle. We benchmark our results for twisted bilayer graphene and twisted
WSe$_2$ bilayers using large-scale molecular dynamics simulations. Our theory
is valid in graphene bilayers for twist angles $\theta \gtrsim 1^\circ$, and in
twisted transition metal dichalcogenides for $\theta \gtrsim 4^\circ$. We also
investigate how relaxation alters the electronic structure in twisted bilayer
graphene, providing a simple extension to the continuum model to account for
lattice relaxation.
