1

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.

5

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}

enter image description here

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
1

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}
    \addtolength{\oddsidemargin}{-13pt}
    \addtolength{\evensidemargin}{-13pt}
    \addtolength{\topmargin}{-4pt}
\usepackage{tikz}% start of required packages
\usepackage{mwe}
\pagestyle{empty}
\begin{document}
\begin{tikzpicture}[remember picture,overlay]
    \node at (current page.center) {\includegraphics[width=\paperwidth,height=\paperheight]{example-image-a}};
\end{tikzpicture}
\end{document}

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.