8

I'm trying to create an image with some text overlaid, similar to the below example. I'm struggling to find something that works, and supports all the formatting I want to include.

Essentially the text box has to support line breaks and be able to centre the text within the box. I'd also like to include a footnote reference, where the footnote appears in the page footer, as normal.

Someone said I could do this using tikz, but I'm really struggling to figure it out. Could I get some help?

Text over image

Ulysses
  • 1,933

1 Answers1

7

The basic concept is explained in Drawing on an image with TikZ. Add the image in a named TikZ node, and place stuff relative to that. (When you know the text should be in a corner there is no need to use the fancy stuff with the scope environment seen in the answers to that question.)

To allow for line breaking, set the text width and/or the align of the node used to hold the text, as in the example below. In that case the node will act sort of like a minipage I think, so a footnote will end up at the bottom of the node, not the page. Using \footnotemark and \footnotetext is a workaround for that, though with floating figures (if you're using that) that leads to problems of their own.

enter image description here

\documentclass{article}
\usepackage{tikz,graphicx}
\begin{document}
\begin{tikzpicture}
\node (img) {\includegraphics[width=8cm]{demo}};
\node [below left,text width=3cm,align=center] at (img.north east){Lorem ipsum dolor sit amet consectetur and then a bunch more stuff that no one remembers.\footnotemark};
\end{tikzpicture}
\footnotetext{Sure about this?}
\end{document}
Torbjørn T.
  • 206,688
  • why does it shift my image if i do the same ? add the text node – Kong Jan 12 '21 at 18:22
  • @Kong I don't know exactly what you did, but if you placed the text node such that it goes outside the boundaries of the image node, that will increase the total width of the tikzpicture, and that might in turn change where on the page the image node ends up. Depending on how the tikzpicture is aligned on the page, and where the text is in relation to the image. For example, if the tikzpicture is placed in a normal paragraph, and the text is placed to the left of the image, then the image by necessity will go further right on the page. – Torbjørn T. Jan 12 '21 at 18:38