# spacing between lines/paragraphs with tikz

I know that when I include graphs/tikz, first LaTeX calculate the space needed for the graph. If there is not enough space, it pushes the graph to the next page. And to make the first page looks nicer, it automatically sets the space between lines/paragraphs. Is there a way to stop this? Something tells me it is a quick/short command :( but I can't find it. As you can see in the picture, the spacing is not nice at all.

Thank you.

Also, can someone show me the way to copy and paste my LaTeX code so that it appears legible in this Ask Question box? Thanks.

\documentclass[twoside]{book}

\usepackage{ tikz, pgfplots}

\usepackage{lipsum}

\pagestyle{empty}
\usepackage{cancel}

\begin{document}

\section{LaTeX Spacing Issues}

\lipsum[1]

%\begin{example}
\textbf{Main Example:}
several texts and equations here. It seems that if there is not enough space for the graph, then LaTeX automatically adjust the space between lines/graphs.

$y = x$
Another equation,
$y = x^2$

$\begin{tikzpicture}[x=1cm,y=0.07cm] \def\xmin{0} \def\xmax{10} \def\ymin{0} \def\ymax{120} % grid \draw[style=help lines, ystep=10, xstep=1] (\xmin,\ymin) grid (\xmax,\ymax); % axes \draw[->] (\xmin,\ymin) -- coordinate (x axis mid) (\xmax+.5,\ymin) node[below] {x}; \draw[->] (\xmin,\ymin) -- coordinate (y axis mid) (\xmin,\ymax+5) node[left] {y}; % xticks and yticks \foreach \x in { 1, 2, ..., 10} \node at (\x, \ymin) [below] {\x}; \foreach \y in {20, 40, ..., 120} \node at (\xmin,\y) [left] {\y};t \draw[scale=1,domain=0:10,smooth,variable=\x,blue, thick] plot ({\x},{12*\x}); \foreach \Point in {(1,12), (2,24), (3,36), (4,48), (5,60), (6,72), (7, 84)}{ \node at \Point {\textbullet}; \node[below=.5cm] at (x axis mid) {Number of visitors}; \node[left=.8cm,rotate=90] at (y axis mid) {Money taken }; } \end{tikzpicture}$
%\end{example}

\subsection*{New section}
\lipsum[1]

• There is \vfill\pagebreak[3] – John Kormylo Mar 31 '15 at 5:07
• Put \raggedbottom in preamble. – user11232 Mar 31 '15 at 5:26
• If you indent lines by 4 spaces, they'll be marked as a code sample. You can also highlight the code and click the "code" button (with "{}" on it). You can use backticks  to mark your inline code – user11232 Mar 31 '15 at 7:42
• never leave a blank line before $ or have one \[ immediately after the previous $, the vertical spacing will always be wrong. Don't put the tikzpicture in $ either. – David Carlisle Mar 31 '15 at 8:04 ## 1 Answer The book class inserts flushbottom by default in an attempt to make the last line of each page to be at the bottom. This can be prevented by issuing \raggedbottom in the preamble. . . . \raggedbottom \begin{document} . . .  However, since you are inserting a picture, you better not use the display math mode in this case. Instead of \[....$, you can use figure environment and let the picture float. This way you are making use of abilities of latex in placing pictures. Also, with figure environment comes \caption macro which you can use for a short description of the picture and what more, you can insert a \label and refer to this picture else where.

\documentclass[twoside]{book}

\usepackage{ tikz, pgfplots}

\usepackage{lipsum}

\pagestyle{empty}
\usepackage{cancel}

\raggedbottom
\begin{document}

\section{LaTeX Spacing Issues}

\lipsum[1]

%\begin{example}
\textbf{Main Example:}
several texts and equations here. It seems that if there is not enough space for the graph, then LaTeX automatically adjust the space between lines/graphs.
%% no blank line be left here
$y = x$
Another equation,
$y = x^2$
%% no blank line be left here
\begin{figure}[htb]
\centering
\begin{tikzpicture}[x=1cm,y=0.07cm]
\def\xmin{0}
\def\xmax{10}
\def\ymin{0}
\def\ymax{120}

% grid
\draw[style=help lines, ystep=10, xstep=1] (\xmin,\ymin) grid (\xmax,\ymax);

% axes
\draw[->] (\xmin,\ymin) -- coordinate (x axis mid) (\xmax+.5,\ymin) node[below] {$x$};
\draw[->] (\xmin,\ymin) -- coordinate (y axis mid) (\xmin,\ymax+5) node[left] {$y$};

% xticks and yticks
\foreach \x in { 1, 2, ..., 10}
\node at (\x, \ymin) [below] {\x};
\foreach \y in {20, 40, ..., 120}
\node at (\xmin,\y) [left] {\y};t
\draw[scale=1,domain=0:10,smooth,variable=\x,blue, thick] plot ({\x},{12*\x});

\foreach \Point in {(1,12), (2,24), (3,36), (4,48), (5,60), (6,72), (7, 84)}{
\node at \Point {\textbullet};
\node[below=.5cm] at (x axis mid) {Number of visitors};
\node[left=.8cm,rotate=90] at (y axis mid) {Money taken };
}
\end{tikzpicture}
\caption{This is a nice picture}
\end{figure}
%\end{example}

\subsection*{New section}
\lipsum[1]
\end{document}
`