TeX graphicx changing page margins

Software

graphicx is the de facto standard for including images in (La)TeX documents. But I noticed on the weekend that importing the package resulted in the margins in the document shifting:

\documentclass[12pt]{memoir}
\usepackage[b5paper]{geometry}
\usepackage{graphicx}

I’d been using this for years, so the behavior surprised me. I swapped the document type back to book, and changed my beloved b5paper size to a4paper without any difference. I thought maybe some images were stretching the margins somewhere, but removing the aforementioned visual depictions them also did nothing.

Importing the paper geometry after graphicx fixed it:

\documentclass[12pt]{memoir}
\usepackage{graphicx}
\usepackage[b5paper]{geometry}

Or defining it in your documentclass if it’s supported:

\documentclass[12pt,b5paper]{memoir}
\usepackage{graphicx}

I love writing in LaTeX, but I always forget small things like this.

Author bio and support

Me!

Ruben Schade is a technical writer and infrastructure architect in Sydney, Australia who refers to himself in the third person. Hi!

The site is powered by Hugo, FreeBSD, and OpenZFS on OrionVM, everyone’s favourite bespoke cloud infrastructure provider.

If you found this post helpful or entertaining, you can shout me a coffee or send a comment. Thanks ☺️.