[Tex/LaTex] How to place an “Export as PDF + Latex from Inkscape”-image above a \includegraphics image (overlay) – Make centers match

graphicspdftexsvg

When you save images as a PDF, checking the PDF + Latex option, one gets 3 files:

  • filename.pdf
  • filename.pdf_tex
  • filename.svg

If you'd like to include this exported image in a Tex document, this is fairly easy provided that the 3 files above are in the same folder as the Tex document you are working in, as follows:

\documentclass{article}
\usepackage{graphicx}
\begin{document}
\input{filename.pdf_tex}
\end{document}

Let's say we have another image titled "another-image.jpg". We could e.g. add it to the document by using \includegraphics{another-image.jpg}.

But, what if we would like to print the image from \input{filename.pdf_tex} right on top (overlay on) of \includegraphics{another-image.jpg}? How is that possible?

The following doesn't do the trick (it will just output the another-image next to the filename-image):

\documentclass{article}
\usepackage{graphicx}
\begin{document}
\includegraphics{another-image.jpg}
\input{filename.pdf_tex}
\end{document}

Let's assume both of the images have equal relative dimensions, and one would like them scaled exactly the same, and put the center of the one right on top of the center of the other.

Best Answer

If one wants to have the images to be of width \linewidth, one can issue the following code in the main Tex document:

\documentclass{minimal}
\usepackage{graphicx, color}

\begin{document}
\def\svgwidth{\linewidth}
\input{filename.pdf_tex}
\end{document}

Then, one needs to adapt the code of the file filename.pdf_tex in e.g. the following manner:

  • Look for the line of code that starts with \put(0,0){\includegraphics and which contains {filename.pdf}.
  • Now, one can enter the following above that line of code:

\put(0,0){\includegraphics[width=\linewidth]{another-image.jpg}}

Then, one can always scale the images further jointly, and re-position them jointly in the main document; e.g. by issuing them within e.g. a parbox-, minipage- and/or figure-environment.

Related Question