6

I am generating a large number of graphics using tikz which I will need to reuse through various places in my document, as well as in animations. Thus, I am pre-creating all these plots. To assure that all page sizes are the same in the plots, I am using the geometry package. Horizontal centering is easy, but even after a lot of looking I could not figure out how to vertically center a tikz graphic on the entire page. Here is an example:

\documentclass{article}
\usepackage{tikz}
\usepackage[ paperwidth=4cm,paperheight=4cm]{geometry}

\begin{document}

\begin{center}
\begin{tikzpicture}
    \draw node[fill,circle,minimum size=2cm] {};
\end{tikzpicture}
\end{center}

\end{document}

Which makes this:

enter image description here

How to get the node in the exact center of the page?

2 Answers 2

6

Using the current page Node (see §17.13.2 of tikz doc) :

\documentclass{article}
\usepackage{tikz}
\usepackage[ paperwidth=4cm,paperheight=4cm]{geometry}

\begin{document}

\begin{tikzpicture}[remember picture, overlay]
    \draw node[fill,circle,minimum size=2cm] at (current page.center) {};
\end{tikzpicture}

\end{document}

enter image description here

With 2 nodes in the same tikzpicture :

\documentclass{article}
\usepackage{tikz}
\usepackage[ paperwidth=4cm,paperheight=4cm]{geometry}

\begin{document}

\begin{tikzpicture}[remember picture, overlay]
  \draw node[fill,circle,minimum size=2cm] at (current page.center) {};
  \draw node[fill=blue, rectangle, minimum size=2cm] at
  (current page.north) {};
\end{tikzpicture}

\end{document}

enter image description here

And With 2 tikzpicture :

\documentclass{article}
\usepackage{tikz}
\usepackage[ paperwidth=4cm,paperheight=4cm]{geometry}
\begin{document}

\begin{tikzpicture}[remember picture, overlay]
  \draw node[fill,circle,minimum size=2cm] at (current page.center) {};
  \draw node[fill=blue, rectangle, minimum size=2cm] at
  (current page.north) {};
\end{tikzpicture}


\begin{tikzpicture}[remember picture, overlay]
  \draw node[fill=red, circle,minimum size=5mm, anchor=south west,
  xshift=5mm, yshift=5mm] at
  (current page.south west) {};
\end{tikzpicture}

\end{document}

enter image description here

2
  • This is great, but what happens when my graphic consists of more than one node?
    – Wapiti
    Oct 24, 2016 at 16:55
  • Wapiti See my update
    – flav
    Oct 25, 2016 at 19:07
3

Up to \topmargin, etc.

\documentclass{article}
\usepackage{tikz}
\usepackage[ paperwidth=4cm,paperheight=4cm]{geometry}

\begin{document}
\null
\vfill
\begin{center}
\begin{tikzpicture}
    \draw node[fill,circle,minimum size=2cm] {};
\end{tikzpicture}
\end{center}
\vfill
\end{document}

enter image description here

2
  • Is there no actual command for this? Because when I compile that code it does not create a node that is centered, only quasi-centered. Plus it appears that I will have to manually fiddle with every image I create, which will be a bit pain...
    – Wapiti
    Oct 24, 2016 at 16:40
  • @Wapiti You can make a macro with picture as a parameter. My centers, but in the text area. There is also place for footers and headers, usually assymetric. Oct 24, 2016 at 16:45

You must log in to answer this question.

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