tikz add tag
Diaa
For the following, how can I perfectly center both vertically and horizontally the drawing since it seems to be slightly shifted up and left?

![texstudio_EfiTAz_1.jpg](/image?hash=152044873c58e2f951bf500fe7837515f313a722aea752080fd4d709e0625724)

```
\documentclass{article}
 
\usepackage{pgfplots}
\usepackage{siunitx}
\usepackage[type=none]{fgruler}
 
\usepackage[
a4paper , includeheadfoot , right = 10mm , left = 10mm , top = 0 mm, headheight = 0 mm, headsep = 5 mm, foot = 5 mm, bottom = 0 mm, showframe
]{geometry}
 
% http://tex.stackexchange.com/a/15002/100384
\newcommand*{\getlength}[2]{%
    % Convert to `cm` and round to two fractional digits:
    \pgfmathsetmacro#1{round(0.0351459804*#2)}%
}
 
\pagestyle{empty}
 
\begin{document}
    \vspace*{\fill}\vskip-\topskip
    \centering
    \begin{tikzpicture}
    \pgfmathsetmacro{\Hfactor}{0.95}% 0.9
    \pgfmathsetmacro{\Wfactor}{0.95}
    \getlength{\yMax}{\Hfactor*\textheight}
    \getlength{\xMax}{\Wfactor*\textwidth}
    \begin{axis}[
    set layers,
    width=\Wfactor\textwidth, height=\Hfactor\textheight,
    scale only axis, name=border,
    x = 1cm, y = 1cm,
    xtick={0,1,...,\xMax},
    ytick={0,1,...,\yMax},
    minor xtick={0,0.1,0.2,...,\xMax},
    minor ytick={0,0.1,0.2,...,\yMax},
    tick style = {line width = 0.6pt, black!40!white},
    minor tick style = {draw = none},
    major tick style = {draw = none},
    ticklabel style = {draw = none},
    xticklabels=\empty,
    yticklabels=\empty,
    axis line style = {-latex},
    grid = both,
    minor grid style={line width=0.2pt, black!20!white},
    major grid style={line width=0.6pt, black!60!white},
    ymin=0, ymax=\yMax,
    xmin=0, xmax=\xMax,
    ]
    \begin{pgfonlayer}{axis grid}
    \draw[line width=0.40pt, step=0.5cm, black!40!white] (axis cs: 0, 0) grid (axis cs: \xMax, \yMax);
    \end{pgfonlayer}
    \end{axis}
    %        \pgfresetboundingbox
    %        \path (border.south west) (border.north east);
    %        \draw[red] (current bounding box.south west) rectangle (current bounding box.north east);
    \end{tikzpicture}\vspace*{\fill}
    \fgruler{lowerleft}{10mm}{5mm}
    \fgruler{upperright}{10mm}{5mm}
\end{document}
```
Top Answer
Diaa
I received [an answer](https://tex.stackexchange.com/a/530044/2288) on TEX.SX as follows:

```
\documentclass[a4paper]{article}
\usepackage{pgfplots}
\usepackage{siunitx}
% http://tex.stackexchange.com/a/15002/100384
\newcommand*{\getlength}[2]{%
   % Convert to `cm` and round to two fractional digits:
   \pgfmathsetmacro#1{round(0.0351459804*#2)}%
}
\newsavebox{\gridbox}
\savebox\gridbox{\begin{tikzpicture}
    \pgfmathsetmacro{\width}{\paperwidth-2cm}
    \pgfmathsetmacro{\height}{\paperheight-2cm}
        % we will need some length in `cm`, without units, and rounded
        \getlength{\yMax}{\height}
        \getlength{\xMax}{\width}
        \begin{axis}[
            set layers,
            width=\width, height=\height,
            scale only axis, name=border,
            x = 1cm, y = 1cm,
            xtick={0,1,...,\xMax},
            ytick={0,1,...,\yMax},
            minor xtick={0,0.1,0.2,...,\xMax},
            minor ytick={0,0.1,0.2,...,\yMax},
            tick style = {line width = 0.6pt, black!40!white},
            minor tick style = {draw = none},
            major tick style = {draw = none},
            ticklabel style = {draw = none},
            xticklabels=\empty, %xlabel = \empty,
            yticklabels=\empty, %ylabel = \empty,
            axis line style = {-latex},
            grid = both,
            minor grid style={line width=0.2pt, black!20!white},
            major grid style={line width=0.6pt, black!60!white},
            ymin=0, ymax=\yMax,
            xmin=0, xmax=\xMax,
            ]
        %\begin{pgfonlayer}{axis grid}% redundant
        %\draw[line width=0.40pt, step=0.5cm, black!40!white] (axis cs: 0, 0) grid (axis cs: \xMax, \yMax);
        %\end{pgfonlayer}
        \end{axis}
    \pgfresetboundingbox
    \path (border.south west) (border.north east);
\end{tikzpicture}}
\pagestyle{empty}
\begin{document}
\begin{tikzpicture}[remember picture,overlay]
  \node at (current page.center) {\usebox\gridbox};
\end{tikzpicture}
\end{document}
```

Or

```
\documentclass[a4paper]{article}
\usepackage{pgfplots}
\usepackage{siunitx}
% http://tex.stackexchange.com/a/15002/100384
\newsavebox{\gridbox}
\savebox\gridbox{\begin{tikzpicture}
        % we will need some length in `cm`, without units, and rounded
		\pgfmathsetmacro{\xMax}{round((\paperwidth-2cm)/1cm)}
		\pgfmathsetmacro{\yMax}{round((\paperheight-2cm)/1cm)}
        \begin{axis}[
            set layers,
            width=\paperwidth-2cm, height=\paperheight-2cm,
            scale only axis, name=border,
            x = 1cm, y = 1cm,
            xtick={0,1,...,\xMax},
            ytick={0,1,...,\yMax},
            minor xtick={0,0.1,0.2,...,\xMax},
            minor ytick={0,0.1,0.2,...,\yMax},
            tick style = {line width = 0.6pt, black!40!white},
            minor tick style = {draw = none},
            major tick style = {draw = none},
            ticklabel style = {draw = none},
            xticklabels=\empty, %xlabel = \empty,
            yticklabels=\empty, %ylabel = \empty,
            axis line style = {-latex},
            grid = both,
            minor grid style={line width=0.2pt, black!20!white},
            major grid style={line width=0.6pt, black!60!white},
            ymin=0, ymax=\yMax,
            xmin=0, xmax=\xMax,
            ]
        %\begin{pgfonlayer}{axis grid}% redundant
        %\draw[line width=0.40pt, step=0.5cm, black!40!white] (axis cs: 0, 0) grid (axis cs: \xMax, \yMax);
        %\end{pgfonlayer}
        \end{axis}
    \pgfresetboundingbox
    \path (border.south west) (border.north east);
\end{tikzpicture}}
\pagestyle{empty}
\begin{document}
\begin{tikzpicture}[overlay,remember picture]
  \node at (current page.center) {\usebox\gridbox};
\end{tikzpicture}
\end{document}
```

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.