The stocksize package provides robust control of the physical PDF page size (the stock size) inside a LaTeX document.
It complements the geometry package by managing paper size transitions reliably, including nested changes, while delegating margin and layout calculations to geometry.
The package is designed for documents where the physical page size itself must change mid-document, such as appendices, inserts, or mixed-format publications.
- Stock size = physical PDF page dimensions
- Layout = (logical) paper height and width, margins, text block, headers/footers (handled by
geometry) stocksizecoordinates both, ensuring they remain synchronized
- Appendices with different paper formats
- Mixed A4 / A5 / Letter documents
- Landscape or square inserts
- Print-ready PDFs with non-uniform stock
- Publisher workflows requiring strict PDF page dimensions
- Logical page size control (via
geometry) - Physical page size control (PDF page dimensions)
- Fully nested size changes (LIFO stack semantics)
- *Optional margin preservation
- Reliable restoration of previous sizes
- Transparent integration with
geometry - Engine-independent (pdfLaTeX, XeLaTeX, LuaLaTeX)
- Documented design with rationale and implementation notes
Place stocksize.sty in your working directory or a LaTeX-visible path.
Load the package in the preamble with:
\usepackage[OPTIONS]{stocksize}The package loads geometry automatically if needed.
Starts a new physical page with the specified stock size and geometry options.
Internally:
- Saves the current page and layout state
- Applies
geometrywith the provided options - Updates the PDF page dimensions
Options
All options are passed directly to geometry, except keepmargins which are processed by the package.
Common examples:
| Option | Meaning |
|---|---|
layoutsize={w,h} |
Set physical page size |
paperwidth=… / paperheight=… |
Alternative size specification |
margin=… |
Uniform margins |
keepmargins |
Preserve current margins |
Example
\newstocksize{layoutsize={20cm,25cm}, margin=2cm}Restores the previous stock size and layout.
- Operates in Last-In-First-Out (stack) order
- Safe for arbitrarily deep nesting
- Restores both geometry and PDF page size
Example
\newstocksize{layoutsize={15cm,10cm}, margin=1.5cm}
Content...
\newstocksize{layoutsize={20cm,20cm}, keepmargins}
Nested content in 20x20 cm stock and paper size...
\restorestocksize
Back to 15×10 cm stock and paper size...
\restorestocksize
Back to the initial stock and paper size...geometryalone does not safely support nested page size changesstocksizeprovides a stack-based abstraction on top ofgeometry- All layout computation remains delegated to
geometry stocksizeensures page size and layout state remain consistent
- PDF page size is set using:
\pdfpagewidth/\pdfpageheight(pdfLaTeX)\pagewidth/\pageheight(XeLaTeX, LuaLaTeX)
- Geometry states are saved and restored explicitly
- No grouping tricks or output-routine hacks are used
The full technical documentation, including design rationale and edge-case discussion, is available in:
stocksize-doc.pdf
- Version: 2.0.0 (2025-12-31)
- Author: João M. Lourenço
- License: LPPL v1.3c or later
- Dependencies:
geometry - Engines: pdfLaTeX, XeLaTeX, LuaLaTeX
Bug reports, tests, and design discussions are welcome via GitHub issues.
Copyright © 2025-26 João M. Lourenço.
Crafted with 🧡 for reproducible scientific writing.