# Insert graphic with tikz without margin

I have to insert a graphic into the whole page with tikz. The graphic has the same size as the final document. I use tikz because I have to insert some drawing and some text into the graphic. My problem now is, that some margin is inserted to. How to avoid this margin?

\documentclass{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage[
total={512pt,512pt},
papersize={512pt,512pt}]{geometry}
\usepackage{tikz}
\usepackage{mwe}
\pagestyle{empty}
\setlength{\parindent}{0cm}
\begin{document}
\begin{tikzpicture}
\node (0,0) {\includegraphics[width=512pt,height=512pt]{example-image-a}};
\end{tikzpicture}
\end{document}


My problem is that the image doesn't fit. The warning says overfull hbox and I get an empty first page.

If you want to creat a document with only one page and sized according size of an inserted graphic, standalone class can help you. It crops the output file to contents.

Following code uses TiKZ to insert a graphics as a tikzpicture node. Every node contains certain inner sep between its contents and border. With inner sep=0pt there won't be any white margin around the inserted graphics.

Being the inserted graphic node, it can be used as reference for adding text or paintings over it.

\documentclass{standalone}
\usepackage[utf8]{inputenc}% start of gratuitous packages
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}
\node[inner sep=0pt] (graphic) {\includegraphics{example-image-a}};
\draw[red, line width=1mm] (graphic.center) circle (13mm);
\node[draw, fill=white, below right=1cm of graphic.north] {this is some text};
\node[draw, rounded corners, fill=green!20, above right=15mm and 2cm of graphic.south west] {$\sin^2 x+\cos^2 x = 1$};
\end{tikzpicture}
\end{document}


An alternative solution could be using incgraph package. Some examples:

• node[inner sep=0pt] was the clue. I didn't think of it. That was exactly, what I was looking for. – Thomas Sablik Apr 6 '16 at 13:29

It takes two runs to locate the image correctly.

\documentclass{scrartcl}
\usepackage[utf8]{inputenc}% start of gratuitous packages
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage[
total={512pt,512pt},
papersize={512pt,512pt}]{geometry}