# vspace Before TikZ Picture

I am trying to make TikZ diagrams such that there is always 1cm of vertical space before the drawing. Is this possible?

This code does not compile.

\documentclass{article}

\usepackage{tikz}

\renewcommand{\begin{tikzpicture}}
{\vspace{1cm} \begin{tikzpicture}}

\begin{document}

text before
\begin{tikzpicture}
\draw(-3,3)--(2,1);
\end{tikzpicture}
text after

\end{document}

• may be you mean \renewenvironment there and sure not \renewcommand ... – koleygr Sep 2 '17 at 19:15
• I just tried changing it to \renewenvironment but it still does not work. – WeCanLearnAnything Sep 2 '17 at 19:20
• You shouldn't do this. Redefining tikzpicture in this way can only give grief. Define a new environment that you use either instead or around tikzpicture. – Ulrike Fischer Sep 2 '17 at 19:21
• Yes... but this is the way to change an environment. You can not do it with renewcommand. Just trying to find a way (Many environments refuse to renew) – koleygr Sep 2 '17 at 19:23

As @UlrikeFischer advices, is easier to define your tikzpicture:

\documentclass{article}

\usepackage{tikz}

\newenvironment{mytikzpicture}{\begin{center}\begin{tikzpicture}}
{\
\end{tikzpicture}\end{center}\vspace*{1cm}

}

\begin{document}

text before

\begin{mytikzpicture}
\draw(-3,3)--(2,1);
\end{mytikzpicture}
text after
\end{document}


Output:

For them who really want the space before (and not after) tikzpicture the code is:

\documentclass{article}

\usepackage{tikz}

\newenvironment{mytikzpicture}{\vspace*{1cm}

\begin{center}\begin{tikzpicture}}
{\
\end{tikzpicture}\end{center}
}

\begin{document}

text before
\begin{mytikzpicture}
\draw(-3,3)rectangle(2,1);
\end{mytikzpicture}
text after
\end{document}

• Awesome, thanks! I had completely forgot about \renewcommand as I hadn't used it in forever. – WeCanLearnAnything Sep 2 '17 at 19:39
• Welcome. \renewenvironment is also a good command but many environments are refusing to renew... and in these cases @UlrikeFischer's advice is really helpful. – koleygr Sep 2 '17 at 19:42

You could also change the current bounding box just before the tikzpicture is closed with execute at end picture option. This option can be applied or not on tikzpicture parameters.

Following example enlarges tikzpictures to north with 1cm space. show background rectangle provides visibility to the change.

\documentclass[border=2mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{backgrounds}

\tikzset{%
execute at end picture={\path (current bounding box.north)--++(0,1cm);
}
},
background rectangle/.style={fill=blue!30}
}

\begin{document}

\begin{tikzpicture}[add1cm, show background rectangle]
\draw (0,0) rectangle (3,2);
\end{tikzpicture}

\begin{tikzpicture}[show background rectangle]
\draw (0,0) rectangle (3,2);
\end{tikzpicture}
\end{document}


• How can I change this example to add space at the bottom (e.g. south instead of north? I tried to replace box.north with box.south but that does not yield any effect. – lanoxx Aug 26 '18 at 14:26
• @lanoxx did you also change (0,1) by (0,-1)? – Ignasi Aug 26 '18 at 16:37
• Ah, it did not occur to me that I had to use a negative value, using a negative value works. Thanks a lot. – lanoxx Aug 26 '18 at 16:57