迷你页面层叠在 TikZ 图像上

迷你页面层叠在 TikZ 图像上

我有一个包含一些文本的缩略图,以及一张用 TikZ 创建的图像。图像中有很多空白,我想将部分文本叠加在图像的空白之上。这类似于 Powerpoint 中可以使用图层执行的操作。

通过创造性地使用hspace,这里有一个简单的解决方案,可以产生我想要的结果:

\hspace{4.3in}\parbox{2.5cm}{%
\tikz blah blah blah
}
\hspace{-5.3in}\begin{minipage}[t]{0.8\textwidth}
text text text text
\end{minipage}

这感觉很老套——虽然能用,但不够优雅。我想知道有没有更简单的方法可以做到这一点,或者这是“更简单的方法”吗?

答案1

另一种方法需要对您的代码进行少量更改(如果我正确理解了您的设置)。在包含 TikZ 代码的宏中,不要包含\begin{tikzpicture}\end{tikzpicture}

当你只需要图像时,写\tikz {\imagecode}。当你需要图表中的其他内容时,使用类似

\begin{tikzpicture}
\imagecode
\node at (x,y) {...};
\end{tikzpicture}

下面是一个简单的示例和输出:

在此处输入图片描述

\documentclass{article}
\usepackage{tikz,lipsum}
\newcommand\imagecode{
\fill [blue!10] (0,0) -- (1,0.5) -| (3,0) -- cycle;
\fill [red!10] (0,0) -- (1,0.5) |- (0,4) -- cycle;
\draw [very thick] (0,0) |- (1,4) |- (3,0.5) |- cycle;
}
\begin{document}
Some text here, then one instance of the diagram.
\begin{center}
\tikz{\imagecode}
\end{center}
Then some more text, and another instance of the diagram, with some additional text.
\begin{center}
\begin{tikzpicture}
\imagecode
\node [below left,xshift=3cm,text width=4.5cm,font=\tiny] at (current bounding box.north east) {\lipsum[2]};
\end{tikzpicture}
\end{center}

\end{document}

答案2

从评论中可以看出,tikz 图像本身在宏中,因此无法直接添加文本。但 tikzpictures 可以嵌套,因此一种方法是在宏图片所在的位置创建新图片。

\documentclass{article}
\usepackage{tikz}
\usepackage{lipsum}
%%%
\newcommand\tikzfigmacro{%
  \begin{tikzpicture}
    \draw[fill=blue,opacity=0.7] (4,0) circle (1cm);
  \end{tikzpicture}
}
%%%
\begin{document}
\begin{tikzpicture}
  \path (0,0) node[anchor=south west]{%
    \begin{minipage}{0.5\linewidth}
      \lipsum[1]
    \end{minipage}
  };
  \path (2,3) node[anchor=south west]{\tikzfigmacro};
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容