I'm trying to draw a textbox over an image like this:

enter image description here

Here's what I have so far:




  \begin{tikzpicture}[y=0.80pt, x=0.80pt, yscale=-1, xscale=1, inner sep=0pt, outer sep=0pt]
    % IMAGE
    \node[anchor=north west,inner sep=0] at (0,0) {\includegraphics[scale=3.0]{example-image-c}};
    \path[draw=foreground,fill=background,line width=1.600pt]
      (232,465) rectangle (512,586);
    \path[draw=foreground,fill=background,line width=0.800pt]
      (241,476) rectangle (502,576);
    % TITLE
    \path[fill=foreground] (340.3773,522.9204) node[above right] (text3826) {TITLE};
    \path[fill=foreground] (331.4183,546.7606) node[above right] (text3830) {SUBTITLE};


How do I:

  1. Horizontally center OUTER RECTANGE within IMAGE.
  3. Center TITLE and SUBTITLE within INNER RECTANGLE as shown.

I don't want to use precise coordinates like (241,476) all over the place. Any alternative ways of drawing this (even without TikZ) would be welcome!

  • Please can you make your code compilable and use an image we all have, such as example-image or example-image-c or whatever? – cfr Aug 19 '18 at 11:54
  • @cfr's proposal is better, but if you really need to put the boxes at these coordinates, just put them at the center of the coordinates and assign them the necessary minimum width and minimum height. – user121799 Aug 19 '18 at 15:58

I'd name the node with the image and then place the other things relative to that, using positioning and fit. The picture then consists of three nodes: the picture, the box with text and a box with the thick outer line.

\begin{tikzpicture}[inner sep=0pt, outer sep=0pt, text=foreground, draw=foreground, fill=background, font=\sffamily\LARGE]
  \node (n) {\includegraphics{example-image}};
  \node (o) [draw, fill, double distance=2.5ex, double=background, line width=.8pt, inner ysep=20pt, inner xsep=50pt, anchor=south, above=5ex of n.south, align=center] {TITLE\\SUBTITLE};
  \node [draw, line width=1.6pt, fit=(o), inner sep=1.25ex] {};

nodes in layers

| improve this answer | |
  • Thanks, positioning and fit are exactly what is needed here! – kontextify Aug 20 '18 at 8:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.