[Tex/LaTex] How to properly include tikz pictures in other tex files

page-breakingtikz-pgf

I figured out a strange behavior of my Latex document and can't explain it. The following code illustrates that. I have text and want to illustrate it with a complex tikz picture, which I shifted to another file because it needs very much space. Now if I create a pdf out of it I get three pages even though all contents fit to one page. I can't explain why that happens. Does anybody of you know?

Main File:

\documentclass{book}
\usepackage{pgf}
\usepackage{tikz}
\usetikzlibrary{shapes,external}
\tikzexternalize
\usepackage{lipsum}
\tikzset{naming/.style={align=center,font=\footnotesize}}
\tikzset{area/.style = {draw, shape = regular polygon, regular polygon sides = 6, thick, minimum width = 5cm}}
\begin{document}
\lipsum[2]

\include{tikzcode}

\lipsum[2]
\end{document}

Simplified tikz file:

\begin{figure}[htb]
\centering
\begin{tikzpicture}[font=\footnotesize]
\node [area] at (0,0) (cell1) {};
\end{tikzpicture}
\caption{test}
\label{fig:test}
\end{figure}

If I include the tikz picture into the main file I get the one-sided pdf I want to have. But due to the fact that the picture is very extensive it would lead to a very confusing long document, because I have several pictures I want to include in that way and always the same happens.

Thank you very much for your help.
Martin

Best Answer

So, the answer should simply be: Change \include to \input.

\documentclass{book}
\usepackage{pgf}
\usepackage{tikz}
\usetikzlibrary{shapes,external}
\tikzexternalize
\usepackage{lipsum}
\tikzset{naming/.style={align=center,font=\footnotesize}}
\tikzset{area/.style = {draw, shape = regular polygon, regular polygon sides = 6, thick, minimum width = 5cm}}
\begin{document}
\lipsum[2]

\input{tikzcode} % that does not insert page breaks

\lipsum[2]
\end{document}