# \begin{figure}… \end{figure} is not working with tikz package

In am using \usepackage{tikz} to draw tikzpicture and it works properly. but if I try to insert figure using \begin{figure} ...\end{figure} an error '\begin{document} ends with \end{figure}' occurs. If I remove \usepackage{tikz} then I am able to insert figure but now error occurs in tikzpicture.

\documentclass[oneside,12pt,a4paper]{book}
\usepackage{UTMThesis}
\usepackage{tikz}
\begin{document}
\centering
\begin{tikzpicture}

%**************** Chapter 1(blocks\nodes***************%
\draw node[draw, below of=title, align=center] (int)at (-1,-0.7) {Chapter 1 };
\draw node[draw, below of=int,align=center] (c12) at (-7,-2.8) {A};
\draw node[draw, below of=int, align=center] (c13) at (-5,-4.3) {B};
\draw node[draw, below of=int, align=center] (c14) at (-3,-2.8) {C};
\draw node[draw, below of=int, align=center] (c15) at (-1,-4.3) {D};
\draw node[draw, below of=int, align=center] (c16) at (1,-2.8) {E};
\draw node[draw, below of=int, align=center] (c17) at (4,-2.8) {F};
%************for arrow/lines**************%
\draw[->, to path={-| (\tikztotarget)}](int.south) -- ++(0,-0.5) edge (c12);
\draw[->, to path={-| (\tikztotarget)}](int.south) -- ++(0,-0.5) edge (c13);
\draw[->, to path={-| (\tikztotarget)}](int.south) -- ++(0,-0.5) edge (c14);
\draw[->, to path={-| (\tikztotarget)}](int.south) -- ++(0,-0.5) edge (c15);
\draw[->, to path={-| (\tikztotarget)}](int.south) -- ++(0,-0.5) edge (c16);
\draw[->, to path={-| (\tikztotarget)}](int.south) -- ++(0,-0.5) edge (c17);

\end{tikzpicture}

\end{document}


Can anyone help me? Thanks in advance Kind regards Bibigul

• Did you add \end{figure} after \end{tikzpicture} and before \end{document}? – cfr Mar 17 '18 at 4:39
• No, If you mean extra \end{figure}? – Bibigul Mar 17 '18 at 4:42
• Where does package UTMThesis comes from? Do you have a link to it? – Kurt Mar 17 '18 at 4:50
• What do you mean by 'extra'? There is no \end{figure} in your code. If you add \begin{figure}, you need an \end{figure} to match. Otherwise, you'll get an error. However, you surely don't want this picture in a figure, since it appears to be a chapter title. – cfr Mar 17 '18 at 5:01
• I had no issue putting this code in a figure. The drawing code itself has some problems. In particular, it draws the path from (int.south) to a point .5cm below that 6 times and also each of the paths from that point overlap. The nodes have both an explicit placement (the at) and a below of. The below of isn't necessary. The align is only necessary for multiline text. – TH. Mar 17 '18 at 5:09

No errors in your tag, I've inserted just \begin{figure}...\caption{...}\end{figure} for testing issue, no errors on it. Can you elaborate your requirement? See the below codea what I tried:

\documentclass[oneside,12pt,a4paper]{book}
%\usepackage{UTMThesis}%%Just comment it to check the output
\usepackage{tikz}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}

%**************** Chapter 1(blocks\nodes***************%
\draw node[draw, below of=title, align=center] (int)at (-1,-0.7) {Chapter 1 };
\draw node[draw, below of=int,align=center] (c12) at (-7,-2.8) {A};
\draw node[draw, below of=int, align=center] (c13) at (-5,-4.3) {B};
\draw node[draw, below of=int, align=center] (c14) at (-3,-2.8) {C};
\draw node[draw, below of=int, align=center] (c15) at (-1,-4.3) {D};
\draw node[draw, below of=int, align=center] (c16) at (1,-2.8) {E};
\draw node[draw, below of=int, align=center] (c17) at (4,-2.8) {F};
%************for arrow/lines**************%
\draw[->, to path={-| (\tikztotarget)}](int.south) -- ++(0,-0.5) edge (c12);
\draw[->, to path={-| (\tikztotarget)}](int.south) -- ++(0,-0.5) edge (c13);
\draw[->, to path={-| (\tikztotarget)}](int.south) -- ++(0,-0.5) edge (c14);
\draw[->, to path={-| (\tikztotarget)}](int.south) -- ++(0,-0.5) edge (c15);
\draw[->, to path={-| (\tikztotarget)}](int.south) -- ++(0,-0.5) edge (c16);
\draw[->, to path={-| (\tikztotarget)}](int.south) -- ++(0,-0.5) edge (c17);
\end{tikzpicture}
\caption{This is for test}
\end{figure}

\end{document}

• @Mady Yuvi, actually I cann't comment \usepackage{UTMThesis}. There must be some thing in UTMThesis.sty. – Bibigul Mar 17 '18 at 7:54
• @Bibigul then please advise where to get that .sty file? – MadyYuvi Mar 17 '18 at 8:14

your use of tikz syntax wrong. for example:

\draw node[draw, below of=title, align=center] (int) at (-1,-0.7) {Chapter 1 };


since text width=<width> is not defined the align=center is superfluous (node size is determined by node content size, so there is nothing to center), but the main problem is positioning of nodes:

• title is not defined so below of=title has no sense
• positioning with at (-1,-0.7) is intended to use only for nodes and not for command \draw node ....

correct code for this line is:

\draw (-1,-0.7) node[draw] (int) {Chapter 1}


or

\node[draw] (int) at (-1,-0.7) {Chapter 1}


beside this, your image present tree with forked edges. such tikzpicture is far more simple to draw by use of tikz tree and tikz library trees:

\documentclass[oneside,12pt,a4paper]{book}
%\usepackage{UTMThesis}%%Just comment it to check the output
\usepackage{tikz}
\usetikzlibrary{trees}

\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}[
every node/.style = {draw},
level distance = 22mm,
sibling distance = 15mm
]
\node {Chapter 1}
[edge from parent fork down]
child { node {A}}
child { node {B}}
child { node {C}}
child { node {D}}
child { node {E}}
child { node {F}};
\end{tikzpicture}
\caption{This is for test}
\end{figure}

\end{document}


it might be that your used picture code is cause of your problems (i'm not sure, since i cant test it UTMThesis package). i don't see, that with above well determined image code you will have reported problems.