# Minipage layered over a TikZ image

I have a minipage of some text, and an image created in TikZ. The image has a bunch of white space in it, and I'd like to overlay part of the text on top of the image's white space. This is similar to what one can do with layers in Powerpoint.

With some creative use of hspace, here's a simple solution that produces exactly what I want:

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


This feels very hacky—it works but is inelegant. I was wondering if there was an easier way to do this, or if this was the "easier way"?

• Just use tikz to place it on top of the tikz image to make one large image. You can handily place a minipage in a node – daleif Sep 29 '16 at 17:25
• @ daleif That is a perfectly good solution in general. Unfortunately, I use the TikZ image in question so much that I made a macro for it. Putting all of the code into the file itself would be even less elegant. – SteelAngel Sep 29 '16 at 17:31
• @StevenB.Segletes I couldn't find \stackindent in the package's documentation, but apparently the author changed a lot of the syntax in a recent update. This looks promising, though. – SteelAngel Sep 29 '16 at 17:36
• It's my own package and I misspoke (ACK!!)...it is \stackinset. There are various examples on this site. Search this site for user:25858 \stackinset tikz and get a list. Here's one example: tex.stackexchange.com/questions/119871/… – Steven B. Segletes Sep 29 '16 at 17:37
• You might try adjusting the bounding box or using a clip rectangle to remove all the white space. – John Kormylo Sep 30 '16 at 4:42

An alternative approach that requires a small change in your code (if I understood your setup correctly). In the macro containing the TikZ code, don't include \begin{tikzpicture} and \end{tikzpicture}.

Whenever you need just the image, write \tikz {\imagecode}. When you need something additional in the diagram, use something like

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


A simple example and output below:

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

• This is a really clever solution. I like it! – SteelAngel Oct 11 '16 at 11:53

From the comments it is seen that the tikz image itself is in a macro, and therefore it is not possible to add the text directly. But tikzpictures can be nested, so one way is to make a new picture where the macro picture is positioned.

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


• They can, but in general avoid nesting. See tex.stackexchange.com/questions/51193/… and linked questions. I don't really see why one would do it in this case either, place the text in a node with text width defined (which makes it similar to a minipage, and place the other stuff relative to it. – Torbjørn T. Sep 30 '16 at 16:47