Skip to content

Instantly share code, notes, and snippets.

@BastiTee
Last active June 9, 2025 17:31
Show Gist options
  • Save BastiTee/5c1d239ddca54de1b4b1241ead8caa1f to your computer and use it in GitHub Desktop.
Save BastiTee/5c1d239ddca54de1b4b1241ead8caa1f to your computer and use it in GitHub Desktop.
How to create a Pinterest Layout with LaTeX
out/
.DS_Store

A Pinterest-like dynamic image layout for TeX

Features

  • Pinterest-like image layouts
  • Up to 8 images per page
  • Works dynamically with different numbers of pictures
  • Fully automated layouting. Only file paths must be provided
  • Vanilla TeX tooling available in texlive

All example images taken from Unsplash

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ENVIRONMENT SETUP
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\documentclass{article}
% Include and manipulate graphics
\usepackage{graphicx}
% Required for custom document command
\usepackage{tikz}
% Required to support optional command arguments
\usepackage{xparse}
% Hide page numbers
\pagenumbering{gobble}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% CUSTOM LAYOUT COMMAND
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\NewDocumentCommand{\PinterestGrid}{g+g+g+g+g+g+g+g}{%
\begin{tikzpicture}
% Column Left
{
\IfValueT{#1}{
\node[anchor=north west] (Left1) at (0,0) {
\includegraphics[width=0.48\textwidth]{#1}
};
}
\IfValueT{#3}{
\node[anchor=north west] (Left2) at (Left1.south west) {
\includegraphics[width=0.48\textwidth]{#3}
};
}
\IfValueT{#5}{
\node[anchor=north west] (Left3) at (Left2.south west) {
\includegraphics[width=0.48\textwidth]{#5}
};
}
\IfValueT{#7}{
\node[anchor=north west] (Left4) at (Left3.south west) {
\includegraphics[width=0.48\textwidth]{#7}
};
}
}
% Column Right
{
\IfValueT{#2}{
\node[anchor=north west] (Right1) at (0.5\textwidth,0) {
\includegraphics[width=0.48\textwidth]{#2}
};
}
\IfValueT{#4}{
\node[anchor=north west] (Right2) at (Right1.south west) {
\includegraphics[width=0.48\textwidth]{#4}
};
}
\IfValueT{#6}{
\node[anchor=north west] (Right3) at (Right2.south west) {
\includegraphics[width=0.48\textwidth]{#6}
};
}
\IfValueT{#8}{
\node[anchor=north west] (Right4) at (Right3.south west) {
\includegraphics[width=0.48\textwidth]{#8}
};
}
}
\end{tikzpicture}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% MAIN DOCUMENT
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\PinterestGrid
{img00001.jpeg}
{img00002.jpeg}
{img00003.jpeg}
{img00004.jpeg}
{img00005.jpeg}
{img00006.jpeg}
{img_blank.jpeg}
{img00007.jpeg}
\end{document}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment