0

I am using tikz to draw a tikzpicture and it works properly. However, if I try to insert a figure using the syntax

\begin{figure} ...\end{figure}

I get the error

\begin{document} ends with \end{figure}

If I remove \usepackage{tikz} then I am able to insert the figure but an 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}
            \begin{figure}[tbh]
\centering
    \includegraphics[scale=0.4]{example-image}
\end{figure}

    \end{document}

Can anyone help me? Thanks in advance.

UTMthesis.sty is here

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% The package UTMthesis.sty will produce the output    %

% of a thesis according to UTM Thesis Manual,          %  

% School of Graduate Studies, 2007.                    %

% Yusof Yaacob, Department of Mathematical Sciences,   %

% Faculty of Science,  Universiti Teknologi Malaysia   %

% 81310 Johor Bahru, Malaysia                          %

% e-mail: [email protected]                               %

% 24 December 2009                                     %

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% LaTeX cod for chapter header

\makeatletter
\def\@makechapterhead#1{
  %\vspace*{20\p@}   %  \vspace*{15\p@}
  {\parindent \z@ 
      \centering  
    \normalfont
    \ifnum \c@secnumdepth >\m@ne
      \if@mainmatter

      \normalsize 
           \bfseries \@chapapp\space \thechapter 
       \par\nobreak
              \vskip 1.4\baselineskip 
      \fi
    \fi
    \interlinepenalty\@M
    \normalsize     
         \bfseries #1\par\nobreak 
       \vskip 1.4\baselineskip %
  }}
\def\@schapter#1{\if@twocolumn
                   \@topnewpage[\@makeschapterhead{#1}]%
                 \else
                   \@makeschapterhead{#1}
                   \@afterheading
                 \fi}
\def\@makeschapterhead#1{
  %\vspace*{20\p@} % \vspace*{20\p@} %
  {\parindent \z@  
    \centering  
    \normalfont 
    \interlinepenalty\@M
    \normalsize 
    \bfseries  #1\par\nobreak
         \vskip 1.4\baselineskip  
  }}
\makeatother
\renewcommand{\chaptername}{CHAPTER}
%------------------------------------------------------------
% Commands for layout
   %\setlength{\topmargin}{-1.2cm}
   %\setlength{\oddsidemargin}{1.7cm}   %\setlength{\oddsidemargin}{1.46cm} 
\setlength{\textwidth}{14.5cm}
   \setlength{\textheight}{24.5cm} %  \setlength{\textheight}{24.5cm}
   %\setlength{\headheight}{2mm}
    %\setlength{\headsep}{10.175mm}
%-------------------------------------------------------------
% Command for 1.5 spacing
   %\renewcommand{\baselinestretch}{1.5}
\usepackage{doublespace}
\setstretch{1.5}
%-------------------------------------------------------------
% Command for  indentation
   \setlength\parindent{.5in}
   \usepackage{indentfirst} %1st line indented after section...
%-------------------------------------------------------------
% Command for space between paragraph
  \makeatletter
    %\setlength{\parskip}{1.5\baselineskip \@plus 3ex
                %  \@minus 2.0ex}
    \setlength{\parskip}{2\baselineskip \@plus .01ex
                  \@minus .01ex}
   \makeatother
%-------------------------------------------------------------
% Commands for no hyphenation and right justified
    \hyphenpenalty=10000 \sloppy
    \raggedbottom
%-------------------------------------------------------------
% Command to get rid of default running head
   \pagestyle{myheadings}
%-------------------------------------------------------------
% Command for  page number 
%  \makeatletter
%    \renewcommand{\ps@plain}{%
%    \renewcommand{\@oddhead}{\hfill\textrm{\thepage}}
%    \renewcommand{\@evenhead}{\@oddhead}
%    \renewcommand{\@evenfoot}{}
%    \renewcommand{\@oddfoot}{}  }
%   \makeatother
%-----------------------------------------------------------------

 %For section font
 % \usepackage{sectsty} 
  %  \chapterfont{\centering\normalsize\uppercase}
  %  \sectionfont{\normalsize\uppercase}
   % \subsectionfont{\normalsize}
   % \subsubsectionfont{\itshape\normalsize}
%---------------------------------------------------------
%--------------------------------------------------------------
% Commands for REFERENCES name
\renewcommand{\bibname}{REFERENCES}
%--------------------------------------------------------------
% Commands to change vertical space in section and subsection
\makeatletter
\renewcommand{\section}{\@startsection
  {section}%      % the name
  {1}             % the level
  {0cm}           % the indent
  {1.0cm}         % the beforeskip
  {0.01cm}    %{0.5cm}    % the afterskip
  {\normalfont\normalsize\bfseries} } % the style
\renewcommand{\subsection}{\@startsection
  {subsection}%   % the name
  {2}             % the leve2
  {0cm}           % the indent
  {1.0cm}         % the beforeskip
  {0.01cm} %{0.5cm}        % the afterskip
  {\normalfont\normalsize\bfseries} } % the style
\makeatother
%--------------------------------------------------------------
% Commands to change horizontal space in section and subsection
% for times romans
   \renewcommand{\thesection} % space between sect. etc.
     {\thechapter.\arabic{section}\hspace{.12in}}
    \renewcommand{\thesubsection} 
       {\thesection\hspace{-.3cm}.\arabic{subsection} \hspace{-.135cm}} 
%--------------------------------------------------------------
% Commands for  TocLoFT
  \usepackage{tocloft}
    %\cftsetrmarg{2.75cm} %    
     \cftsetrmarg{1.5cm} %  
       \cftsetpnumwidth{1.25cm} 
       %\cftsetpnumwidth{1.25cm}
    \renewcommand{\cftdot}{} % get rid of dots
%Table of Contents
\renewcommand{\contentsname}{}        % off tocname
\setlength{\cftchapindent}{.8cm}      % chapter indent
\setlength{\cftsecindent}{2.3cm}      % section indent
\setlength{\cftsubsecindent}{3.25cm}  % subsection indent
\setlength{\cftchapnumwidth}{1.45cm}  % chp number width
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%  \renewcommand{\cftchapafterpnum}{\rule{1.75ex}{0ex}}
%   \renewcommand{\cftsecafterpnum}{\rule{1.75ex}{0ex}}
%   \renewcommand{\cftsubsecafterpnum}{\rule{1.75ex}{0ex}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  \renewcommand{\cftchapafterpnum}{\rule{0.75ex}{0ex}}
   \renewcommand{\cftsecafterpnum}{\rule{0.75ex}{0ex}}
   \renewcommand{\cftsubsecafterpnum}{\rule{0.75ex}{0ex}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   \renewcommand{\cftchappagefont}{\normalfont}
%-------------------------------------------------------------  
%List of Table
\setlength{\cfttabnumwidth}{2.5cm}  %\setlength{\cfttabnumwidth}{2.5cm}  
\renewcommand{\listtablename}{} % off lotname
%\setlength{\cfttabindent}{-.015cm}      % table indent %%%%%%%%%%%%%%%%%%
\setlength{\cfttabindent}{-.1cm}      % table indent %%%%%%%%%%%%%%%%%%
             \renewcommand{\cfttabafterpnum}{\rule{2ex}{0ex}}
\cftsetrmarg{3cm}
%------------------------------------------------------------
 %List of Figure
\setlength{\cftfignumwidth}{2.5cm}
\renewcommand{\listfigurename}{} % off lofname
\setlength{\cftfigindent}{-.1cm}      % figure indent %%%%%%%%%%%%%%%%%%
   \renewcommand{\cftfigafterpnum}{\rule{2ex}{0ex}}
%-------------------------------------------------------------
%-------------------------------------------------------------
% Command for bold caption
\makeatletter
  \long\def\@makecaption#1#2{\vskip 10\p@   % caption parameter
       \setbox\@tempboxa\hbox{{#1\,\,\,\,\,} #2} %%%%%
       \ifdim \wd\@tempboxa >\hsize         % caption parameter
           {#1\,\,\,\,\,}  #2\par  % caption parameter
       \else                                   % caption parameter
           \hbox to\hsize{\hfil\box\@tempboxa\hfil}  % caption parameter
   \fi}                                            % caption parameter
\makeatother   
\renewcommand{\thefigure}{\arabic{chapter}.\arabic{figure}}
\renewcommand{\thetable}{\arabic{chapter}.\arabic{table}}
%--------------------------------------------------------------
\usepackage{paralist} %refine list item
%--------------------------------------------------------------
\usepackage{latexsym,amsmath,amssymb} % math symbols
%--------------------------------------------------------------
\usepackage{graphicx} % .eps graphic
%--------------------------------------------------------------
\usepackage{lscape} % for landscape
%-------------------------------------------------------------- 
\usepackage{times}
%--------------------------------------------------------------
% Theorem-Like-Environment
\usepackage{theorem}
{\theorembodyfont{\upshape}
\newtheorem{lemma}{Lemma}[chapter]
\newtheorem{theorem}{\rule{0ex}{5ex}Theorem}[chapter]
\newtheorem{corollary}{Corollary}[chapter]
\newtheorem{proposition}{Proposition}[chapter]
\newtheorem{definition}{\rule{0ex}{5ex}Definition}[chapter]
\newtheorem{example}{Example}[chapter] }
%--------------------------------------------------------
\newenvironment{proof}{\begin{paragraph}
          {Proof}\vspace{-1cm}}{\end{paragraph}}
\newenvironment{solution}{\begin{paragraph}
          {Solution}\vspace{-1cm}}{\end{paragraph}}
%-----------------------------------------------------------

Kind regards, Bibigul

3
  • No, If you mean extra \end{figure}?
    – Bibigul
    Mar 17, 2018 at 4:42
  • 1
    Your package UTMthesis is irrelevant to your image. Your example (see my answer below) compile fine with and without it. If you still have problems in your document, their source is not in this image. From showed error follows, that somewhere in document you have a figure, which is not terminated with \end{figure}. Since we don know your document, we can't help you to find this.
    – Zarko
    Feb 16, 2020 at 10:22
  • @Zarko I tried your example but it is not working. I edited my post you can chek it now. my document is working properly. There are many figures in my whole document and working perfectly. Now, I want to draw a tikzpicture but it is not working. It only works when i comment all the figures.
    – Bibigul
    Feb 17, 2020 at 0:55

2 Answers 2

3

Edit:

  • Inserting your tikzpicure in the figure float environment doesn't cause any error, using your UTMThesis package or not
  • Your picture code is not cause of your problems
  • Somewhere in your document you not terminated figure float with \end{figure}. From your MWE (Minimal Working Example) cannot be seen where this is in your document. Your MWE not contain figure float.

Off-topic: Your picture code is strange ... used syntax is 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 shorter

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

Also, drawing lines between nodes is unnecessary complex. It can be simplified (to more clear and shorter way):

\draw[->] (int.south) -- ++(0,-0.5) -| (c12);

Considering aforementioned, the MWE is:

\documentclass[oneside,12pt,a4paper]{book}
\usepackage{UTMThesis}
\usepackage{tikz}

\begin{document}
    \centering
    \begin{tikzpicture}[
every node/.style = {draw}
                        ]
%**************** Chapter 1(blocks\nodes***************%
\node   (int) at (-1,-0.7) {Chapter 1 };
\node   (c12) at (-7,-2.8) {A};
\node   (c13) at (-5,-4.3) {B};
\node   (c14) at (-3,-2.8) {C};
\node   (c15) at (-1,-4.3) {D};
\node   (c16) at (1,-2.8)  {E};
\node   (c17) at (4,-2.8)  {F};
%************for arrow/lines**************%
\draw[->] (int.south) -- ++(0,-0.5) -| (c12);
\draw[->] (int.south) -- ++(0,-0.5) -| (c13);
\draw[->] (int.south) -- ++(0,-0.5) -| (c14);
\draw[->] (int.south) -- ++(0,-0.5) -| (c15);
\draw[->] (int.south) -- ++(0,-0.5) -| (c16);
\draw[->] (int.south) -- ++(0,-0.5) -| (c17);
    \end{tikzpicture}
\end{document}

which gives:

enter image description here

Your image present a tree with forked edges. It can be far more simple as such with use of the tikz library trees:

\documentclass[oneside,12pt,a4paper]{book}
\usepackage{UTMThesis}
\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}

enter image description here

2

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .