4

The way I’ve programmed in TikZ so far (but maybe I have been missing something), I have never heard of ways to tell TikZ where to put the origin of the coordinate system on the printed page. But there are many situations where I would like to. For example, in the minimal example below, part of the picture is eaten up on the right margin and I exclaim "Why doesn’t TikZ push the figure a little to the left so that everything gets displayed ?"

How does TikZ transfer the coordinate system to the printed page by default? This is probably explained somewhere in the manual, but I got somewhat lost searching through the index as I didn’t know which keyword to look for.

Any help appreciated.

\documentclass[a4paper]{article}
\usepackage{tikz}

\begin{document}
\begin{center}
\begin{tikzpicture}
   \foreach \x in {0,2,4,6,8}  {
     \draw (2*\x,0) -- ++(1,1);
  }
  \end{tikzpicture}
\end{center}
\end{document}
1
  • There are a few words about it in the documentation of the tikzpicture environment (12.2), but I guess there is more somewhere else.
    – T. Verron
    Oct 10, 2014 at 9:24

1 Answer 1

7

Any tikzpicture is considered like a character in LaTeX. There is no fixed relation between tikzpicture coordinates and the printed page unless your force it (explained later).

\documentclass{article}
\usepackage{tikz}
\begin{document}

This is an example
\begin{tikzpicture}
\draw (0,0) rectangle (2,2);
\end{tikzpicture}
with a \texttt{tikzpicture} inside.
\end{document}

enter image description here

Your example is too wide (more then 17cm) to fit in \linewidth (you must consider left and right page margins) and part of it is eaten.

If you want to work with your figure without to worry about page dimensions, can use standalone package/class which with your example produces:

\documentclass[tikz,border=2mm]{standalone}

\begin{document}
\begin{tikzpicture}
   \foreach \x in {0,2,4,6,8}  {
     \draw (2*\x,0) -- ++(1,1);
  }
  \end{tikzpicture}
\end{document}

enter image description here

Now this external figure (pdf) can be inserted in your text with \includegraphics command (may be inside a figure environment). It can also be included as tikzpicture with \usepackage{standalone} in your main document preamble and \input{your_file}. In both cases the figure will be treated as a character.

It's also possible to place the tikzpicture on fixed positions as is explained in pgfmanual section 17.13.2. Another opction could be to use a package like background.

\documentclass[4paper]{article}
\usepackage{tikz}

\begin{document}
This is an example with
\begin{tikzpicture}[remember picture,overlay]
   \draw (current page.center) rectangle ++(2,2);
  \end{tikzpicture}
  a \texttt{tikzpicture} absolutely positioned.
\end{document}

enter image description here

2
  • "There is no fixed relation between tikzpicture coordinates and the printed page." ... except for the current page node (which you mention).
    – T. Verron
    Oct 10, 2014 at 10:26
  • @T.Verron You're right, I've included your point.
    – Ignasi
    Oct 10, 2014 at 10:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .