# remove white space above and below

I have a TikZ graphical code, but when I generate the pdf file there is some white space above and below the figure that I want to remove. I tried to use the \clip command but I don't know how to use it (actually I don't know to place the rectangle coordinates in such a way to remove the unwanted space).

Here is my LaTeX code:

%\makeatletter\let\ifGm@compatii\relax\makeatother
%\useoutertheme{split}

\makeatletter\let\ifGm@compatii\relax\makeatother
\documentclass[11pt]{beamer}
%
\usepackage{times}
\usepackage[english]{babel}
\usepackage{pgf,pgfarrows,pgfnodes,pgfautomata,pgfheaps}
\usepackage{amsmath,amssymb}
\usepackage[latin1]{inputenc}
\usepackage{geometry}
\usepackage{tikz}

\usepackage{lmodern}

\usetikzlibrary{decorations.pathmorphing}
\usetikzlibrary{shapes}
\tikzset{snake it/.style={decorate, decoration=snake}}

%\setcounter{MaxMatrixCols}{10}
\tikzset{cross/.style={cross out, draw,
minimum size=2*(#1-\pgflinewidth),
inner sep=0pt, outer sep=0pt}}
\usetikzlibrary{arrows}
\tikzset{
LL/.style={
draw=black,decorate,
decoration={snake, segment length=3mm, amplitude=1mm,post length=2mm}
}
}
\begin{document}
%\pagestyle{empty}
%\tikzstyle{int}=[draw, fill=blue!20] \tikzstyle{sous}=[node
%§distance=2.45cm]
% \tikzstyle{init} = [draw,fill=red!20]
\tikzset{->-/.style={decoration={
markings,
mark=at position #1 with {\arrow{>}}},postaction={decorate}}}

\begin{figure}
\centering
\begin{tikzpicture}%[auto,>=latex']

\draw[draw=black, snake it] (12cm,5cm) ;

\draw (-2.8,-0.8) -- (-1.5,-0.8) -- (-1.5,0.8) -- (-2.8,0.8) -- (-2.8,-0.8); %% Transmitter
% \draw (-1.1,0.4) -- (6.8,0.4) ; %%line 1
\draw (-1.04,-0.4) -- (1.35,-0.4) ; %% line 2 1st segment
\draw (1.65,-0.4) -- (5.55,-0.4); %% line 2 contin.
\draw (6.8,-0.8) -- (8.1,-0.8) -- (8.1,0.8) -- (6.8,0.8) -- (6.8,-0.8); %% Receiver
\draw[black, thick] (-1.3,-0.2) -- (-1,-0.2) -- (-1.15,-0.5) -- (-1.3,-0.2); % triangle 1
\draw[black, thick] (5.8,-0.2) -- (5.5,-0.2) -- (5.65,-0.5) -- (5.8,-0.2);  % triangle 2
\draw[black, thick] (-1.5,-0.65) -- (-1.15,-0.65) -- (-1.15,-0.5) ;% antenna 1 support
\draw[black, thick] (6.8,-0.65) -- (6.4,-0.65) ;% antenna 2 support
\draw[black, thick] (6.1,-0.65) -- (5.65,-0.65) -- (5.65,-0.5);% antenna 2 support (2)
\draw[black, thick]  (6.25,-0.65) circle (0.15); %% AWGN
\draw (1.5,-0.4) circle (0.15); %% fading
\draw[black, thick] (6.25,-0.65) node[cross=3.4pt,rotate=45,black]{}; %%  + sign
\draw (1.5,-0.4) node[cross=3.6pt,rotate=0,black]{}; %% x sign

\draw[black, thick] (-1.2,0.7) -- (-0.5,0.7) -- (-0.5,0.4) -- (-1.2,0.4) -- (-1.2,0.7); %% FSO1
\draw[black, thick]  (2.8,1.05) -- (4.9,1.05) -- (4.9,0.05) -- (2.8,0.05) -- (2.8,1.05); %% optical receiver
\draw[black, thick]  (-1.2,0.7) -- (-1.3,0.7) -- (-1.3,0.1) -- (-1.5,0.1) -- (-1.5,0.0)-- (-1.2,0.0) -- (-1.2,0.7); %% FSO2 support

\path[LL,thick]      (-0.4,0.55) -- (0.9,0.55); %% wave 1
\path[LL,thick,->,>=latex]  (1.2,0.55) -- (2.8,0.55); %% wave 1
%\draw[black, thick]  (3.6,0.8) -- (4.4,0.8) -- (4.4,0.3) -- (3.6,0.3) -- (3.6,0.8); %% photodet.
%\draw (2.45,-0.4) -- (5.55,-0.4); %% line between phot. & Amplif.
% \draw[black, thick] (4.8,0.8) -- (5.35,0.55) -- (4.8,0.3) -- (4.8,0.8);  % Amplif.
\draw (6.25,0.55) circle (0.15); %% AWGN2
\draw (6.25,0.55) node[cross=3.4pt,rotate=45,black]{}; %%  + sign (2)
%\draw (3.1,0.55) -- (3.6,0.55); %% line between FSO2. & PD.
\draw (4.9,0.55) -- (6.1,0.55); %% line between PD & AWGN2
\draw (5.35,0.55) -- (6.1,0.55); %% line between Amp & AWGN2
\draw (6.4,0.55) -- (6.8,0.55); %% line between AWGN & MRC

\draw[->] (1.5,-0.85) -- (1.5,-0.55); %% fading arrow
\draw[->] (6.25,-1.1) -- (6.25,-0.8); %% AWGN1 arrow
\draw[->] (6.25,1.0) -- (6.25,0.7); %% AWGN2 arrow

\draw (1.05,0.55) circle (0.15); %% irradiance
\draw[->] (1.05,1.0) -- (1.05,0.7); %% irradiance arrow
\draw (1.05,0.55) node[cross=3.6pt,rotate=0,black]{}; %% x sign
\node[font=\fontsize{8}{8}\selectfont,align=center] at (7.45,0) {MRC \\ Combiner};
\node[font=\fontsize{8}{8}\selectfont,align=center] at (-0.95,1.2) {FSO Laser\\Device};
\node[font=\fontsize{7}{7}\selectfont,align=center,align=center] at (1.22,1.25) {(Irradiance)\\$I=I_lI_aI_p$};
\node[font=\fontsize{7}{7}\selectfont,align=center,align=center] at (1.5,-0.97) {$\alpha_2$}; %% fading alpha2
\node[font=\fontsize{7}{7}\selectfont,align=center,align=center] at (6.25,1.3) {$n\sim(0,\frac{N_0}{2})$}; %% noise1
\node[font=\fontsize{7}{7}\selectfont,align=center,align=center] at (6.25,-1.3) {$n'\sim(0,\frac{N_0}{2})$}; %% noise2
\node[font=\fontsize{8}{8}\selectfont,align=center,align=center] at (-1.57,1.75) {Transmitter};
\node[font=\fontsize{8}{8}\selectfont,align=center,align=center] at (1.25,1.75) {Channel};
%\node[text width=0.8cm,align=center] at (7.4,0) {MRC \\ Combiner};
%\node[text width=0.8cm,align=center] at (7.4,0) {MRC \\ Combiner};
\draw[dashed] (0.1,1.6) -- (-3.1,1.6) -- (-3.1,-1.5) -- (0.1,-1.5) -- (0.1,1.6); %% Transmitter dashed box
\draw[dashed] (0.3,1.6) -- (1.99,1.6) -- (1.99,-1.5) -- (0.3,-1.5) -- (0.3,1.6); %% channel dashed box
\draw[dashed] (2.5,1.6) -- (8.5,1.6) -- (8.5,-1.5) -- (2.5,-1.5) -- (2.5,1.6); %% channel dashed box
\clip (-3,3) rectangle (9,-3);
\end{tikzpicture}%}
\end{figure}
\end{document}

• What is the \draw[draw=black, snake it] (12cm,5cm) ; for? It doesn't seem to do anything (except add a point at (12cm,5cm)). – John Kormylo Jun 8 '17 at 22:59
• \clip only affects stuff later in the picture. It has no effect on anything already drawn. – cfr Jun 8 '17 at 23:43
• @cfr I don't know how to use the \clip command. for example let's take \clip (-3,3) rectangle (9,-3); what does (-3,3) and (9,-3) refers to ? how can I beneficiate from it to remove spaces? – Elmehdi Jun 9 '17 at 0:29
• please fix your example so that it can be run. your tikz is in a figure environment which adds vertical space, by an amount which depends on the \documentclass – David Carlisle Jun 9 '17 at 7:01
• The white space comes from the point at (12,5) already mentioned by John Kormylo and the clip command which enlarges the figure down. Delete both commands and the tikzpicture will keep its correct size. By the way, you're using beamer so the figure should be inside a \begin{frame} ... \end{frame} environment. – Ignasi Jun 9 '17 at 7:45

There are several possibilities. You may comment out the snake-line. You may clip (see comments above) the unwanted white space (please play around with the borders and you see their meaning). Another solution may be the usage of the pgfinterruptboundingbox-environment (please look into the manual for explanations on this).

%\makeatletter\let\ifGm@compatii\relax\makeatother
%\useoutertheme{split}

\makeatletter\let\ifGm@compatii\relax\makeatother
\documentclass[11pt]{beamer}
%
\usepackage{times}
\usepackage[english]{babel}
\usepackage{pgf,pgfarrows,pgfnodes,pgfautomata,pgfheaps}
\usepackage{amsmath,amssymb}
\usepackage[latin1]{inputenc}
\usepackage{geometry}
\usepackage{tikz}

\usepackage{lmodern}

\usetikzlibrary{decorations.pathmorphing}
\usetikzlibrary{shapes}
\tikzset{snake it/.style={decorate, decoration=snake}}

%\setcounter{MaxMatrixCols}{10}
\tikzset{cross/.style={cross out, draw,
minimum size=2*(#1-\pgflinewidth),
inner sep=0pt, outer sep=0pt}}
\usetikzlibrary{arrows}
draw=black,decorate,
decoration={snake, segment length=3mm, amplitude=1mm,post length=2mm}
}
}
\begin{document}
%\pagestyle{empty}
%\tikzstyle{int}=[draw, fill=blue!20] \tikzstyle{sous}=[node
%§distance=2.45cm]
% \tikzstyle{init} = [draw,fill=red!20]
\tikzset{->-/.style={decoration={
markings,
mark=at position #1 with {\arrow{>}}},postaction={decorate}}}

\begin{figure}
\centering
\begin{tikzpicture}%[auto,>=latex']

%  \draw[draw=black, snake it] (12cm,5cm) ;

\clip (-3,3) rectangle (9,-3);

\draw (-2.8,-0.8) -- (-1.5,-0.8) -- (-1.5,0.8) -- (-2.8,0.8) -- (-2.8,-0.8); %% Transmitter
% \draw (-1.1,0.4) -- (6.8,0.4) ; %%line 1
\draw (-1.04,-0.4) -- (1.35,-0.4) ; %% line 2 1st segment
\draw (1.65,-0.4) -- (5.55,-0.4); %% line 2 contin.
\draw (6.8,-0.8) -- (8.1,-0.8) -- (8.1,0.8) -- (6.8,0.8) -- (6.8,-0.8); %% Receiver
\draw[black, thick] (-1.3,-0.2) -- (-1,-0.2) -- (-1.15,-0.5) -- (-1.3,-0.2); % triangle 1
\draw[black, thick] (5.8,-0.2) -- (5.5,-0.2) -- (5.65,-0.5) -- (5.8,-0.2);  % triangle 2
\draw[black, thick] (-1.5,-0.65) -- (-1.15,-0.65) -- (-1.15,-0.5) ;% antenna 1 support
\draw[black, thick] (6.8,-0.65) -- (6.4,-0.65) ;% antenna 2 support
\draw[black, thick] (6.1,-0.65) -- (5.65,-0.65) -- (5.65,-0.5);% antenna 2 support (2)
\draw[black, thick]  (6.25,-0.65) circle (0.15); %% AWGN
\draw (1.5,-0.4) circle (0.15); %% fading
\draw[black, thick] (6.25,-0.65) node[cross=3.4pt,rotate=45,black]{}; %%  + sign
\draw (1.5,-0.4) node[cross=3.6pt,rotate=0,black]{}; %% x sign

\draw[black, thick] (-1.2,0.7) -- (-0.5,0.7) -- (-0.5,0.4) -- (-1.2,0.4) -- (-1.2,0.7); %% FSO1
\draw[black, thick]  (2.8,1.05) -- (4.9,1.05) -- (4.9,0.05) -- (2.8,0.05) -- (2.8,1.05); %% optical receiver
\draw[black, thick]  (-1.2,0.7) -- (-1.3,0.7) -- (-1.3,0.1) -- (-1.5,0.1) -- (-1.5,0.0)-- (-1.2,0.0) -- (-1.2,0.7); %% FSO2 support

\path[LL,thick]      (-0.4,0.55) -- (0.9,0.55); %% wave 1
\path[LL,thick,->,>=latex]  (1.2,0.55) -- (2.8,0.55); %% wave 1
%\draw[black, thick]  (3.6,0.8) -- (4.4,0.8) -- (4.4,0.3) -- (3.6,0.3) -- (3.6,0.8); %% photodet.
%\draw (2.45,-0.4) -- (5.55,-0.4); %% line between phot. & Amplif.
% \draw[black, thick] (4.8,0.8) -- (5.35,0.55) -- (4.8,0.3) -- (4.8,0.8);  % Amplif.
\draw (6.25,0.55) circle (0.15); %% AWGN2
\draw (6.25,0.55) node[cross=3.4pt,rotate=45,black]{}; %%  + sign (2)
%\draw (3.1,0.55) -- (3.6,0.55); %% line between FSO2. & PD.
\draw (4.9,0.55) -- (6.1,0.55); %% line between PD & AWGN2
\draw (5.35,0.55) -- (6.1,0.55); %% line between Amp & AWGN2
\draw (6.4,0.55) -- (6.8,0.55); %% line between AWGN & MRC

\draw[->] (1.5,-0.85) -- (1.5,-0.55); %% fading arrow
\draw[->] (6.25,-1.1) -- (6.25,-0.8); %% AWGN1 arrow
\draw[->] (6.25,1.0) -- (6.25,0.7); %% AWGN2 arrow

\draw (1.05,0.55) circle (0.15); %% irradiance
\draw[->] (1.05,1.0) -- (1.05,0.7); %% irradiance arrow
\draw (1.05,0.55) node[cross=3.6pt,rotate=0,black]{}; %% x sign
\node[font=\fontsize{8}{8}\selectfont,align=center] at (7.45,0) {MRC
\\ Combiner}; \node[font=\fontsize{8}{8}\selectfont,align=center] at
(-0.95,1.2) {FSO Laser\\Device};
\node[font=\fontsize{8}{8}\selectfont,align=center] at (3.83,0.60)
\node[font=\fontsize{7}{7}\selectfont,align=center,align=center] at
(1.22,1.25) {(Irradiance)\\$I=I_lI_aI_p$};
\node[font=\fontsize{7}{7}\selectfont,align=center,align=center] at (1.5,-0.97) {$\alpha_2$}; %% fading alpha2
\node[font=\fontsize{7}{7}\selectfont,align=center,align=center] at (6.25,1.3) {$n\sim(0,\frac{N_0}{2})$}; %% noise1
\node[font=\fontsize{7}{7}\selectfont,align=center,align=center] at (6.25,-1.3) {$n'\sim(0,\frac{N_0}{2})$}; %% noise2
\node[font=\fontsize{8}{8}\selectfont,align=center,align=center] at
(-1.57,1.75) {Transmitter};
\node[font=\fontsize{8}{8}\selectfont,align=center,align=center] at
(1.25,1.75) {Channel};
\node[font=\fontsize{8}{8}\selectfont,align=center,align=center] at