类似图形的环境

类似图形的环境

我有一份包含大量图片但文本不多的文档(每页大约六行)。使用环境figure不是一个选择,因为我无法决定每个图像的位置。现在我只是使用\includegraphics{}

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

所以我精确地选择了每张图片应该在的位置。有没有办法给这些图片编号?我可能会在每个 tikzpicture 内部添加一个类似定理的环境,但它不适用于includegraphics。有没有更好的解决方案?

答案1

如果你真的想把它们紧紧地包装起来,你可以使用如下方法:

\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}

演示


我找到了一种更简单、更紧凑的替代方案。在这里,保存框仅用于使它们更容易移动,并重新排列标题顺序。

\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}

相关内容