0

I have a document with a large number of figures and not much text (about six lines per page). Using the figure environment isn't an option since I can't decide the position of each image. Now I'm just using \includegraphics{} and

\begin{center}
\begin{tikzpicture}
...
\end{tikzpicture}
\end{center}

so I choose exactly where each image should be. Is there a way I can number these images? I might add a theorem-like environment inside each tikzpicture, but it doesn't work for includegraphics. Is there a better solution?

9
  • You could use \captionof{figure}{...} from the caption package Oct 26, 2018 at 15:35
  • Off-topic: \begin{center}...\end{center} adds additional vertical space, I would use \centering instead. Oct 26, 2018 at 15:36
  • Why not use \begin{figure}[H]...\end{figure} and then a regular \caption?
    – Werner
    Oct 26, 2018 at 16:00
  • 2
  • 1
    It's more or less what was said in the previous comments actually, just with some small examples. And yes, you need the float package for [H]. Oct 26, 2018 at 19:41

1 Answer 1

1

If you REALLY want to pack them tightly, you can use something like this:

\documentclass{article} 
\usepackage{tikz}
\usepackage{varwidth}
\usepackage{caption}
\usepackage{lipsum}
\usepackage{showframe}

\begin{document}
\begin{figure}[tp]
\sbox0{\rule{4cm}{2cm}}% normally use a tikzpicture of unknown size
\sbox1{\begin{minipage}{\wd0}
  \usebox0
  \captionof{figure}{First}
\end{minipage}}%
%
\sbox0{\rule{4cm}{4cm}}%
\sbox2{\begin{minipage}{\wd0}
  \usebox0
  \captionof{figure}{Second}
\end{minipage}}%
%
\sbox0{\rule{3cm}{2cm}}%
\sbox3{\begin{minipage}{\wd0}
  \usebox0
  \captionof{figure}{Third}
\end{minipage}}%
%
\sbox0{\rule{3cm}{4cm}}%
\sbox4{\begin{minipage}{\wd0}
  \usebox0
  \captionof{figure}{Fourth}
\end{minipage}}%
%
\sbox0{\rule{\textwidth}{2cm}}
\sbox5{\begin{minipage}{\wd0}
  \usebox0
  \captionof{figure}{Fifth}
\end{minipage}}%
%
\sbox0{\rule{4cm}{2cm}}%
\sbox6{\begin{minipage}{\wd0}
  \usebox0
  \captionof{figure}{Sixth}
\end{minipage}}%
%
\centering
\begin{tikzpicture}[inner sep=0pt, outer sep=0.5\columnsep]
\begin{scope}[local bounding box=S1]
  \node (A) {\usebox1};
  \node[below right] (B) at (A.north east) {\usebox2};
  \node[below right] (C) at (B.north east) {\usebox3};
  \node[below right] (D) at (C.south west) {\usebox4};
  \node[below right] (F) at (A.south west) {\usebox6};
\end{scope}
  \node[below] (E) at (S1.south) {\usebox5};
\end{tikzpicture}
\end{figure}
\lipsum[1-6]
\end{document}

demo


I found a simpler and more compact alternative. Here the saveboxes only serve to make shuffling them around easier, and rearrange the caption order.

\documentclass{article} 
\usepackage{tikz}
\usepackage{varwidth}
\usepackage{caption}
\usepackage{lipsum}
\usepackage{showframe}

\begin{document}
\begin{figure}[tp]
\sbox0{\rule{4cm}{2cm}}% normally use a tikzpicture of unknown size
\sbox1{\begin{minipage}{\wd0}
  \usebox0
  \captionof{figure}{First}
\end{minipage}}%
%
\sbox0{\rule{4cm}{4cm}}%
\sbox2{\begin{minipage}{\wd0}
  \usebox0
  \captionof{figure}{Second}
\end{minipage}}%
%
\sbox0{\rule{3cm}{2cm}}%
\sbox3{\begin{minipage}{\wd0}
  \usebox0
  \captionof{figure}{Third}
\end{minipage}}%
%
\sbox0{\rule{3cm}{4cm}}%
\sbox4{\begin{minipage}{\wd0}
  \usebox0
  \captionof{figure}{Fourth}
\end{minipage}}%
%
\sbox0{\rule{\textwidth}{2cm}}
\sbox5{\begin{minipage}{\wd0}
  \usebox0
  \captionof{figure}{Fifth}
\end{minipage}}%
%
\sbox0{\rule{4cm}{2cm}}%
\sbox6{\begin{minipage}{\wd0}
  \usebox0
  \captionof{figure}{Sixth}
\end{minipage}}%
%
\centering
\raisebox{-\height}{\usebox1}\hfill
\raisebox{-\height}{\usebox2}\hfill
\raisebox{-\height}{\usebox4}

\raisebox{\dimexpr 0.5\depth-0.5\height}{\usebox3}\hfil
\raisebox{\dimexpr 0.5\depth-0.5\height}{\usebox6};

\usebox5
\end{figure}
\lipsum[1-6]
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .