So as far as I know, $$Z=\frac{p_\mathrm{r}V_\mathrm{r}}{nRT},$$ where $\mathrm{r}$ denotes the subscript for real.
Solving it for a van der Waals gas gave me the following result, $$Z=1+\frac{p_\mathrm{r} b}{RT}-\frac{an}{VRT}+\frac{an^2b}{V^2RT},$$ where $V$ is the volume of the container.
This doesn't quite tally with the form I see in the textbooks. Where am I going wrong?