# How can I force a pgfplots graph to be in the center of the page?

using width and height I can make the graph bigger, however if it is made too big the graph will start to shift towards the right and bottem of the page, despite there being plenty of space left on the page up in the top and left of the page. How can I force the graph to always remain in the center (both vertically and horizontally) of the page and not shift itself when its made bigger.

    \begin{tikzpicture}[rotate=90]
\begin{axis}
[
width=24cm, height=17cm,
title={},
xlabel={},
ylabel={},
minor grid style = dashed,
major grid style = draw,
minor tick num = 1,
grid = both,
mark size = 1,
]
table{data.dat};
table[y={create col/linear regression={y=Y}}]{data.dat};
\end{axis}
\end{tikzpicture} An A4 paper page is about 21cm x 29.7cm, you're setting your graph at 17cm x 24cm. This means that you have an extra 4cm in height and 5.7cm in width to play with. Add the fact that you could have margins, and you don't have much left. At that point, you don't have really much for positioning.

The shifting is a result of your huge graph, when compared to the page, conflicting with the margins.

So your solution would be: either reduce your margins, or — in my opinion the best solution — reduce the size of the graph.

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

\pgfplotsset{compat=1.13}

\begin{document}
\begin{figure}[!htb]
\centering
\begin{tikzpicture}

...

\end{tikzpicture}
\end{figure}
\end{document}


This is a minimal example. If you have margins like

\usepackage[<margins>]{geometry}


then you can set an exception for this page, assuming the printer can print that far, by saying

\newgeometry{margin=2cm}
<graph>
\restoregeometry


So that the margins for only that page will be 2cm on all sides.

• Adjusting the size of the margins worked great, thanks! – Syne Mar 12 '16 at 18:10
{"ft_lang_label":"__label__en","ft_lang_prob":0.6639671,"math_prob":0.91262746,"size":856,"snap":"2019-26-2019-30","text_gpt3_token_len":247,"char_repetition_ratio":0.1056338,"word_repetition_ratio":0.0,"special_character_ratio":0.27920562,"punctuation_ratio":0.1534091,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9748103,"pos_list":[0,1,2],"im_url_duplicate_count":[null,1,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2019-07-16T18:22:33Z\",\"WARC-Record-ID\":\"<urn:uuid:facbf412-7b67-4d0b-98c6-69ab0c732995>\",\"Content-Length\":\"145189\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:e91b4215-200b-4bba-aa67-e3ad13f3e14d>\",\"WARC-Concurrent-To\":\"<urn:uuid:48124fba-3392-492d-8acb-c52ffac4b196>\",\"WARC-IP-Address\":\"151.101.129.69\",\"WARC-Target-URI\":\"https://tex.stackexchange.com/questions/298645/how-can-i-force-a-pgfplots-graph-to-be-in-the-center-of-the-page\",\"WARC-Payload-Digest\":\"sha1:K7I3P472PLYGF6AIWWWSBTZQO2YP3UP7\",\"WARC-Block-Digest\":\"sha1:BO57KSQWRD53DHVNUJGRBKGIX2QR52UG\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2019/CC-MAIN-2019-30/CC-MAIN-2019-30_segments_1563195524685.42_warc_CC-MAIN-20190716180842-20190716202842-00407.warc.gz\"}"}