1

I know that it's possible to place an image within a node at precise coordinates, and to scale the image:

\documentclass[10pt]{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[scale=3]
\node at (1,1) {
    \includegraphics[scale=0.3]{"image"}
};
\end{tikzpicture}
\end{document}

However, what I want to do is to choose a rectangle with coordinates and place an image to fit inside:

\documentclass[10pt]{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[scale=3]
\node at (1,1) rectangle (4,4) {
    \includegraphics{"image"}
};
\end{tikzpicture}
\end{document}

Thus, it can precisely be positioned relatively to other elements like lines.

Is it possible to do that?

  • 1
    Please always post compilable code rather than fragments. – cfr Feb 4 '18 at 19:14
  • This doesn't seem to be a duplicate. I already explored that link but all it provides is an answer that uses \textwidth (which isn't what I want because I am looking for coordinates) and a draw command with a path style, but the image doesn't fit inside (unless it is example-image). – Codoscope Feb 4 '18 at 19:35
  • 1
    You don't have to use \textwidth, obviously. You can specify the coordinate however you like. E.g. \path[fill overzoom image=example-image-a] (0,0) rectangle (6,4); substituting 6,4 for \textwidth,4cm. It fits inside for me. Also works with the standard tiger image. If you don't want it cropped in the other direction use e.g. \path[fill stretch image=tiger] (0,0) rectangle (6,4); but, obviously, the image will be distorted in that case. – cfr Feb 4 '18 at 20:07
  • @cfr: it does precisely what I was looking for. Thanks! To sum it up: all I need is to add \usepackage[skins]{tcolorbox} in the header and then write \path[fill stretch image=my_image] (1,1) rectangle (4,4); inside a tikzpicture block. – Codoscope Feb 10 '18 at 16:59

Browse other questions tagged or ask your own question.