Here's a work in progress:
Code
\documentclass{scrartcl}
\usepackage[margin=25.4mm]{geometry}
\usepackage{tikz}
\usepackage{filecontents}
\usepackage{xifthen}
\pgfdeclarelayer{background}
\pgfsetlayers{background,main}
\newcommand{\getsizes}%
{ \path (current bounding box.south west);
\pgfgetlastxy{\xsw}{\ysw}
\path (current bounding box.north east);
\pgfgetlastxy{\xne}{\yne}
\pgfmathsetlengthmacro{\picwidth}{\xne-\xsw}
\pgfmathsetlengthmacro{\picheight}{\yne-\ysw}
\pgfmathsetmacro{\picscale}{\picwidth>\picheight ? (0.3*\textwidth)/\picwidth : (0.3*\textwidth)/\picheight}
\pgfmathsetlengthmacro{\biggervalue}{\picwidth>\picheight ? \picwidth : \picheight}
\xdef\scalefactor{\picscale}
\xdef\picdimension{\biggervalue}
}
\newcommand{\grayback}%
{ \begin{pgfonlayer}{background}
\fill[gray!50] (current bounding box.center) ++(-\picdimension/2,-\picdimension/2) rectangle ++(\picdimension,\picdimension);
\end{pgfonlayer}
}
\newcommand{\adjustedtikzsize}[2]% draw commands, caption
{ \stepcounter{galleryitem}
\smash{\vphantom{
\begin{tikzpicture}
#1
\getsizes
\end{tikzpicture}
}}
\begin{tikzpicture}[scale=\scalefactor]
#1
\grayback
\node[below right] at (current bounding box.south west) {#2};
\end{tikzpicture}
\pgfmathtruncatemacro{\breaktest}{mod(\thegalleryitem,3)}
\ifthenelse{\breaktest=0}{\par}{\hspace{0.02\textwidth}}
}
\newcounter{galleryitem}
\setcounter{galleryitem}{0}
\newenvironment{tikzgallery}[1]% gallery title
{{\Huge\textbf{#1}}\par}%
{\par}
\begin{filecontents}{picone.tex}
\draw[rotate=30,left color=red,right color=blue] (0,0) rectangle (5,2);
\end{filecontents}
\begin{filecontents}{pictwo.tex}
\draw[rotate=20,left color=green,right color=red] (0,0) rectangle (5,2);
\end{filecontents}
\begin{filecontents}{picthree.tex}
\draw[rotate=40,left color=orange,right color=blue] (0,0) rectangle (5,2);
\end{filecontents}
\begin{document}
\parindent0mm
\parskip0mm
\begin{tikzgallery}{Geometrie}
\adjustedtikzsize{\input{picone}}{one}
\adjustedtikzsize{\input{pictwo}}{two}
\adjustedtikzsize{\input{picthree}}{three}
\adjustedtikzsize{\input{pictwo}}{un}
\adjustedtikzsize{\input{picthree}}{deux}
\adjustedtikzsize{\input{picone}}{trois}
\end{tikzgallery}
\end{document}
Result

Edit 1: Now with:
- choosable amount of pictures per row (breaks partially for
n ≥ 10)
- improved alignment
- dynamic spaces between pictures
- environment breaking across pages
;)
Code
\documentclass{scrartcl}
\usepackage[margin=10mm]{geometry}
\usepackage{tikz}
\usepackage{filecontents}
\usepackage{xifthen}
\pgfdeclarelayer{background}
\pgfsetlayers{background,main}
\newcommand{\getsizes}%
{ \path (current bounding box.south west);
\pgfgetlastxy{\xsw}{\ysw}
\path (current bounding box.north east);
\pgfgetlastxy{\xne}{\yne}
\pgfmathsetlengthmacro{\picwidth}{\xne-\xsw}
\pgfmathsetlengthmacro{\picheight}{\yne-\ysw}
%\pgfmathsetmacro{\picscale}{\picwidth>\picheight ? (0.3*\textwidth)/\picwidth : (0.3*\textwidth)/\picheight}
\pgfmathsetmacro{\picscale}{\picwidth>\picheight ? (1.05-\picturesperrow*0.05)/\picturesperrow*\textwidth/\picwidth : (1.05-\picturesperrow*0.05)/\picturesperrow*\textwidth/\picheight}
\pgfmathsetlengthmacro{\biggervalue}{\picwidth>\picheight ? \picwidth : \picheight}
\xdef\scalefactor{\picscale}
\xdef\picdimension{\biggervalue}
}
\newcommand{\grayback}%
{ \begin{pgfonlayer}{background}
\fill[gray!50] (current bounding box.center) ++(-\picdimension/2,-\picdimension/2) rectangle ++(\picdimension,\picdimension);
\end{pgfonlayer}
}
\newcommand{\adjustedtikzsize}[2]% draw commands, caption
{ \stepcounter{galleryitem}
\smash{\vphantom{
\begin{tikzpicture}
#1
\getsizes
\end{tikzpicture}
}}
\begin{tikzpicture}[scale=\scalefactor,baseline=(captionnode.north)]
#1
\grayback
\node[below right] (captionnode) at (current bounding box.south west) {#2};
\end{tikzpicture}
\pgfmathtruncatemacro{\breaktest}{mod(\thegalleryitem,\picturesperrow)}
\ifthenelse{\breaktest=0}{\par}{\hfill}%{\hspace{0.02\textwidth}}
}
\newcounter{galleryitem}
\setcounter{galleryitem}{0}
\newenvironment{tikzgallery}[2]% gallery title, pics per row
{{\Huge\textbf{#1}}\par\xdef\picturesperrow{#2}}%
{\par\vspace{1cm}}
\begin{filecontents}{picone.tex}
\draw[rotate=30,left color=red,right color=blue] (0,0) rectangle (5,2);
\end{filecontents}
\begin{filecontents}{pictwo.tex}
\draw[rotate=20,left color=green,right color=red] (0,0) rectangle (5,2);
\end{filecontents}
\begin{filecontents}{picthree.tex}
\draw[rotate=40,left color=orange,right color=blue] (0,0) rectangle (5,2);
\end{filecontents}
\begin{filecontents}{picfour.tex}
\draw[left color=black!10,right color=black!90] (-1,-7) rectangle (1,7);
\draw[left color=yellow,right color=violet] (0,0) circle (5);
\end{filecontents}
\begin{document}
\parindent0mm
\parskip0mm
\begin{tikzgallery}{Geometrie}{6}
\adjustedtikzsize{\input{picone}}{one}
\adjustedtikzsize{\input{pictwo}}{two}
\adjustedtikzsize{\input{picthree}}{three}
\adjustedtikzsize{\input{picfour}}{four}
\adjustedtikzsize{\input{picfour}}{zero}
\adjustedtikzsize{\input{pictwo}}{un}
\adjustedtikzsize{\input{picthree}}{deux}
\adjustedtikzsize{\input{picone}}{trois}
\adjustedtikzsize{\input{picone}}{one}
\adjustedtikzsize{\input{pictwo}}{two}
\adjustedtikzsize{\input{picthree}}{three}
\adjustedtikzsize{\input{picfour}}{four}
\adjustedtikzsize{\input{picfour}}{zero}
\adjustedtikzsize{\input{pictwo}}{un}
\adjustedtikzsize{\input{picthree}}{deux}
\adjustedtikzsize{\input{picone}}{trois}
\adjustedtikzsize{\input{picone}}{one}
\adjustedtikzsize{\input{pictwo}}{two}
\adjustedtikzsize{\input{picthree}}{three}
\adjustedtikzsize{\input{picfour}}{four}
\adjustedtikzsize{\input{picfour}}{zero}
\adjustedtikzsize{\input{pictwo}}{un}
\adjustedtikzsize{\input{picthree}}{deux}
\adjustedtikzsize{\input{picone}}{trois}
\end{tikzgallery}
\begin{tikzgallery}{Ti\textit{k}Z-Spielerei}{4}
\adjustedtikzsize{\input{picone}}{one}
\adjustedtikzsize{\input{pictwo}}{two}
\adjustedtikzsize{\input{picthree}}{three}
\adjustedtikzsize{\input{picfour}}{four}
\adjustedtikzsize{\input{picfour}}{zero}
\adjustedtikzsize{\input{pictwo}}{un}
\adjustedtikzsize{\input{picthree}}{deux}
\adjustedtikzsize{\input{picone}}{trois}
\adjustedtikzsize{\input{picone}}{one}
\adjustedtikzsize{\input{pictwo}}{two}
\adjustedtikzsize{\input{picthree}}{three}
\adjustedtikzsize{\input{picfour}}{four}
\adjustedtikzsize{\input{picfour}}{zero}
\adjustedtikzsize{\input{pictwo}}{un}
\adjustedtikzsize{\input{picthree}}{deux}
\adjustedtikzsize{\input{picone}}{trois}
\adjustedtikzsize{\input{picone}}{one}
\adjustedtikzsize{\input{pictwo}}{two}
\adjustedtikzsize{\input{picthree}}{three}
\adjustedtikzsize{\input{picfour}}{four}
\adjustedtikzsize{\input{picfour}}{zero}
\adjustedtikzsize{\input{pictwo}}{un}
\adjustedtikzsize{\input{picthree}}{deux}
\adjustedtikzsize{\input{picone}}{trois}
\end{tikzgallery}
\clearpage
\begin{tikzgallery}{Riesige Bilder}{2}
\adjustedtikzsize{\input{picone}}{one}
\adjustedtikzsize{\input{pictwo}}{two}
\adjustedtikzsize{\input{picthree}}{three}
\adjustedtikzsize{\input{picfour}}{four}
\adjustedtikzsize{\input{picfour}}{zero}
\adjustedtikzsize{\input{pictwo}}{un}
\adjustedtikzsize{\input{picthree}}{deux}
\adjustedtikzsize{\input{picone}}{trois}
\end{tikzgallery}
\end{document}
Result

Edit 2: Some explanations, fixed galleryitem counter:
Commented Code
\documentclass{scrartcl}
% should work with all formats and margins, but probably not very well in small spapes
\usepackage[margin=10mm]{geometry}
\usepackage{tikz}
% for creating the dummy .tex files
\usepackage{filecontents}
\usepackage{xifthen}
\pgfdeclarelayer{background}
\pgfsetlayers{background,main}
\newcommand{\getsizes}%
{
% get coordinates of bottom left and top right corner of the bounding box
\path (current bounding box.south west);
\pgfgetlastxy{\xsw}{\ysw}
\path (current bounding box.north east);
\pgfgetlastxy{\xne}{\yne}
% use these to compute height and width of the picture
\pgfmathsetlengthmacro{\picwidth}{\xne-\xsw}
\pgfmathsetlengthmacro{\picheight}{\yne-\ysw}
% as the pictures are going to be set on a gray square, we need the bigger dimension; then the scaleing factor is computed: 5% \textwidth spacing subtracted to make \hfill work correctly, then basically \texttwidth/\picdim
\pgfmathsetmacro{\picscale}{\picwidth>\picheight ? (1.05-\picturesperrow*0.05)/\picturesperrow*\textwidth/\picwidth : (1.05-\picturesperrow*0.05)/\picturesperrow*\textwidth/\picheight}
% find out if height or width is bigger, and save this info and the scale factor in a global macro
\pgfmathsetlengthmacro{\biggervalue}{\picwidth>\picheight ? \picwidth : \picheight}
\xdef\scalefactor{\picscale}
\xdef\picdimension{\biggervalue}
}
\newcommand{\grayback}%
{ \begin{pgfonlayer}{background}
% putting the gray background; \picdimension was set by "\getsizes"
\fill[gray!50] (current bounding box.center) ++(-\picdimension/2,-\picdimension/2) rectangle ++(\picdimension,\picdimension);
\end{pgfonlayer}
}
\newcommand{\adjustedtikzsize}[2]% draw commands, caption
{ \stepcounter{galleryitem}
% make height and width of the box of the tikzpicture 0, also don't print anything; so the picture is "drawn" twice, the first time invisible to get the dimensions for computation of the scaling factor
\smash{\vphantom{
\begin{tikzpicture}
% insert the draw commands
#1
% determine the scaling factor and the bigger of picheight and picwidth; save both to global macros
\getsizes
\end{tikzpicture}
}}
% the same picture again, but this time really drawn, with previousely set scaling factor and baseline option for aligning the pictures
\begin{tikzpicture}[scale=\scalefactor,baseline=(captionnode.north)]
% insert the draw commands
#1
% gray background
\grayback
% caption node
\node[below right] (captionnode) at (current bounding box.south west) {#2};
\end{tikzpicture}
% compute "pic mod picsperrow"; if zero, we need to break the line
\pgfmathtruncatemacro{\breaktest}{mod(\thegalleryitem,\picturesperrow)}
\ifthenelse{\breaktest=0}{\par}{\hfill}
}
%counter to keep track of the gallery items
\newcounter{galleryitem}
\setcounter{galleryitem}{0}
\newenvironment{tikzgallery}[2]% gallery title, pics per row
% ser the title in huge, globally set picsperrow, reset galleryitem counter
{{\Huge\textbf{#1}}\par\xdef\picturesperrow{#2}\setcounter{galleryitem}{0}}%
{\par\vspace{1cm}}
% some dummy .tex files which contain just plain tikz commands, no preamble, no tikzpicture environment
\begin{filecontents}{picone.tex}
\draw[rotate=30,left color=red,right color=blue] (0,0) rectangle (5,5);
\end{filecontents}
\begin{filecontents}{pictwo.tex}
\draw[rotate=20,left color=green,right color=red] (0,0) rectangle (1,9);
\end{filecontents}
\begin{filecontents}{picthree.tex}
\draw[rotate=40,left color=orange,right color=blue] (0,0) rectangle (5,2);
\end{filecontents}
\begin{filecontents}{picfour.tex}
\draw[left color=black!10,right color=black!90] (-1,-7) rectangle (1,7);
\draw[left color=yellow,right color=violet] (0,0) circle (5);
\end{filecontents}
\begin{document}
\parindent0mm
\parskip0mm
\begin{tikzgallery}{Geometrie}{6}
\adjustedtikzsize{\input{picone}}{one}
\adjustedtikzsize{\input{pictwo}}{two}
\adjustedtikzsize{\input{picthree}}{three}
\adjustedtikzsize{\input{picfour}}{four}
\adjustedtikzsize{\input{picfour}}{zero}
\adjustedtikzsize{\input{pictwo}}{un}
\adjustedtikzsize{\input{picthree}}{deux}
\adjustedtikzsize{\input{picone}}{trois}
\adjustedtikzsize{\input{picone}}{one}
\adjustedtikzsize{\input{pictwo}}{two}
\adjustedtikzsize{\input{picthree}}{three}
\adjustedtikzsize{\input{picfour}}{four}
\adjustedtikzsize{\input{picfour}}{zero}
\adjustedtikzsize{\input{pictwo}}{un}
\adjustedtikzsize{\input{picthree}}{deux}
\adjustedtikzsize{\input{picone}}{trois}
\adjustedtikzsize{\input{picone}}{one}
\adjustedtikzsize{\input{pictwo}}{two}
\adjustedtikzsize{\input{picthree}}{three}
\adjustedtikzsize{\input{picfour}}{four}
\adjustedtikzsize{\input{picfour}}{zero}
\adjustedtikzsize{\input{pictwo}}{un}
\adjustedtikzsize{\input{picthree}}{deux}
\adjustedtikzsize{\input{picone}}{trois}
\end{tikzgallery}
\begin{tikzgallery}{Ti\textit{k}Z-Spielerei}{3}
\adjustedtikzsize{\input{picone}}{one}
\adjustedtikzsize{\input{pictwo}}{two}
\adjustedtikzsize{\input{picthree}}{three}
\adjustedtikzsize{\input{picfour}}{four}
\adjustedtikzsize{\input{picfour}}{zero}
\adjustedtikzsize{\input{pictwo}}{un}
\adjustedtikzsize{\input{picthree}}{deux}
\adjustedtikzsize{\input{picone}}{trois}
\adjustedtikzsize{\input{picone}}{one}
\adjustedtikzsize{\input{pictwo}}{two}
\adjustedtikzsize{\input{picthree}}{three}
\adjustedtikzsize{\input{picfour}}{four}
\adjustedtikzsize{\input{picfour}}{zero}
\adjustedtikzsize{\input{pictwo}}{un}
\adjustedtikzsize{\input{picthree}}{deux}
\adjustedtikzsize{\input{picone}}{trois}
\adjustedtikzsize{\input{picone}}{one}
\adjustedtikzsize{\input{pictwo}}{two}
\adjustedtikzsize{\input{picthree}}{three}
\adjustedtikzsize{\input{picfour}}{four}
\adjustedtikzsize{\input{picfour}}{zero}
\adjustedtikzsize{\input{pictwo}}{un}
\adjustedtikzsize{\input{picthree}}{deux}
\adjustedtikzsize{\input{picone}}{trois}
\end{tikzgallery}
\clearpage
\begin{tikzgallery}{Riesige Bilder}{2}
\adjustedtikzsize{\input{picone}}{one}
\adjustedtikzsize{\input{pictwo}}{two}
\adjustedtikzsize{\input{picthree}}{three}
\adjustedtikzsize{\input{picfour}}{four}
\adjustedtikzsize{\input{picfour}}{zero}
\adjustedtikzsize{\input{pictwo}}{un}
\adjustedtikzsize{\input{picthree}}{deux}
\adjustedtikzsize{\input{picone}}{trois}
\end{tikzgallery}
\end{document}
Result

standaloneallows you to include TikZ images or any other TeX file using\includestandalone[<options>}{<filename>}where you can use the same (standard) options like for\includegraphics. Alsoadjustboxis able to turn its content into a float and add a caption. The three-in-a-row format needs extra effort, however. – Martin Scharrer Sep 27 '12 at 15:51\includestandaloneas you suggested. Do you know how I could define a gallery-environment, that adds the \includestandalone + adjustbox automatically? (I've provided the code on github, the link is in my question). By the way, it doesn't have to be 3-in-a-row. It should only fit to the page width. – Martin Thoma Sep 28 '12 at 10:27adjustbox. The result is now much nicers, but I don't know how to fix the size :-( – Martin Thoma Sep 28 '12 at 12:14widthandheightinstead ofmax widthandmax heightto get a fixed size. You need to addkeepaspectratioso that the ratio isn't changed. One side might then be smaller than requested. – Martin Scharrer Sep 28 '12 at 17:57