How to Align an Inkscape PDF+LaTeX Overlay in LaTeX
At a glance
- 1. Prefer one export
Include the generated .pdf_tex file; it positions the Inkscape artwork and LaTeX text together.
- 2. Match the bounds
For separate layers, export both with identical page bounds and use the same displayed width.
- 3. Align the boxes
Place the overlay at the base image’s right edge, with both boxes sharing a baseline.
- 4. Check the result
Compile and inspect the PDF for clipping, duplicate artwork, or a shifted crop.
Inkscape’s PDF+LaTeX export creates two companion files: a PDF containing the non-text artwork and a .pdf_tex file that places the text over that PDF. In most cases, include the .pdf_tex file by itself. LaTeX then handles the artwork and text as one figure, so there is no separate center-alignment step.
If you really do need to place that export over another \includegraphics image, the two layers must use the same crop, aspect ratio, and displayed width. Then place the overlay box at the base image’s edge and align their baselines.
The usual method: include the PDF+LaTeX export as one figure
Suppose Inkscape created diagram.pdf and diagram.pdf_tex. The .pdf_tex file typically includes the companion PDF and positions the text using coordinates from the Inkscape drawing. Include that file with \input:
\documentclass{article}
\usepackage{graphicx}
\usepackage{xcolor}
\begin{document}
\begin{figure}[ht]
\centering
\def\svgwidth{0.7\linewidth}
\input{diagram.pdf_tex}
\caption{A diagram exported from Inkscape.}
\end{figure}
\end{document}
Keep diagram.pdf beside the .tex file and the .pdf_tex file. Set \svgwidth to the desired figure width; the generated code uses it to scale the artwork and its text together. The exact generated commands can vary by Inkscape version, so open the .pdf_tex file if a width setting seems to have no effect. Some versions use a different mechanism for setting the size.
This method is preferable to including the PDF and separately trying to position the labels: the export already records how the text lines up with the drawing.
Overlay a separate image and PDF+LaTeX layer
Sometimes the underlying image is a different file, such as a raster image, and you want to place only selected Inkscape content over it. For this arrangement, use the same width for both layers and ensure that both exports cover the same page rectangle. The following example places the overlay above the base image, with both boxes sharing their right edge and baseline:
\documentclass{article}
\usepackage{graphicx}
\usepackage{xcolor}
\begin{document}
\begin{figure}[ht]
\centering
\includegraphics[width=6cm]{base-image}%
\makebox[0pt][r]{%
\raisebox{0pt}[0pt][0pt]{%
\def\svgwidth{6cm}%
\input{overlay.pdf_tex}%
}%
}%
\caption{A base image with an Inkscape overlay.}
\end{figure}
\end{document}
Here the base image is typeset first. The zero-width \makebox places the overlay at the current point—the base image’s right edge—while [r] makes the overlay extend left from that point. Because both layers are 6 cm wide, their left and right edges match. \raisebox{0pt}[0pt][0pt]{...} keeps the overlay’s height and depth from changing the surrounding line spacing; it does not shift the overlay vertically.
This assumes the generated overlay’s picture box has its baseline at the bottom, as is usual for this kind of export. If the files have different whitespace or crop boundaries, matching widths alone will not align their visible contents. Adjust the export bounds, or inspect the generated .pdf_tex coordinates and correct the offset.
Make a text-only overlay when needed
A PDF+LaTeX export usually contains the non-text Inkscape artwork as well as the LaTeX text. If you place that export over a separate image, the artwork may be drawn a second time. That can cause doubled lines or obscure the image underneath.
For a true text-only overlay, export or prepare an Inkscape layer containing just the labels, while preserving the same page rectangle as the base image. Alternatively, use the complete PDF+LaTeX export as the figure and avoid a separate base image. Check whether the exported PDF has a white background; an opaque background will cover anything beneath it.
Common mistakes
- Using
\includegraphicson the.pdf_texfile. It is a LaTeX source snippet, not an image. Use\input{...}. - Giving the layers different widths. Even if their original centers match, scaling them differently moves the visible content relative to each other.
- Exporting with different bounds. A tight crop around one layer and a full-page export for the other produce different coordinate systems. Use the same page or drawing bounds for both.
- Forgetting the companion PDF. The
.pdf_texfile often refers to the PDF by filename, so keep the companion file in the expected directory and compile with a PDF-capable engine such as pdfLaTeX or LuaLaTeX. - Overlaying a complete export on its own artwork. The PDF portion may redraw the same paths. Use one combined export, or create a genuinely text-only overlay.
If the layers still appear offset, temporarily draw a thin border around each exported page. Misaligned borders reveal whether the problem is box placement or different export bounds; remove the borders after correcting the source files.
Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.