0

I am using ait-thesis template, It gives error when I wrap a tikz picture inside a figure. I tried to add remove package and found that \usepackage{tikz} is in conflict with aitthesis.cls here is the link to class. If I place tikz package before it then problem does not arises but remaining document is all messed up. Real error is too many }s, Latex Error: \begin{document} end with \end{figure}. The error file says: \color@endbox ->\color@endgroup \egroup. Can you please solve it. My code works in standalone document class. Working Example without aitthesis class

\documentclass{article}
 \usepackage{tikz}

 \usetikzlibrary{positioning}
 \begin{document}
 \begin{figure}
\centering
\tikzset{%
neuron missing/.style={
draw=none, 
scale=4,
text height=0.333cm,
execute at begin node=\color{black}$\vdots$
},
}

\begin{tikzpicture}[x=1.5cm, y=1.5cm, >=stealth]

\foreach \m/\l [count=\y] in {1,2,3}
{
\node [circle,fill=green!50,minimum size=1cm] (input-\m) at (0,2.5-\y) {};
}
\foreach \m/\l [count=\y] in {4}
{
 \node [circle,fill=green!50,minimum size=1cm ] (input-\m) at (0,-2.5) {};
}

\node [neuron missing]  at (0,-1.5) {};


\foreach \m [count=\y] in {1}
\node [circle,fill=red!50,minimum size=1cm ] (hidden-\m) at (2,0.75) {};

\foreach \m [count=\y] in {2}
\node [circle,fill=red!50,minimum size=1cm ] (hidden-\m) at (2,-1.85) {};

\node [neuron missing]  at (2,-0.3) {};


\foreach \m [count=\y] in {1}
 \node [circle,fill=blue!50,minimum size=1cm ] (output-\m) at (4,1.5-\y) {};

\foreach \m [count=\y] in {2}
 \node [circle,fill=blue!50,minimum size=1cm ] (output-\m) at (4,-0.5-\y) {};

\node [neuron missing]  at (4,-0.4) {};

\foreach \l [count=\i] in {1,2,3,256}
 \draw [<-] (input-\i) -- ++(-1,0)
 node [above, midway] {$I_{\l}$};

\foreach \l [count=\i] in {1,16}
\node [above] at (hidden-\i.north) {$H_{\l}$};

\foreach \l [count=\i] in {1,16}
\draw [->] (output-\i) -- ++(1,0)
node [above, midway] {$O_{ \l}$};

\foreach \i in {1,...,4}
\foreach \j in {1,...,2}
\draw [->] (input-\i) -- (hidden-\j);

\foreach \i in {1,...,2}
\foreach \j in {1,...,2}
\draw [->] (hidden-\i) -- (output-\j);

 %\foreach \l [count=\x from 0] in {Input, Hidden, Ouput}
 % \node [align=center, above] at (\x*2,2) {\l \\ layer};

\end{tikzpicture}

\caption{Caption}
\label{fig:my_label}
\end{figure}

\end{document} 
  • https://tex.stackexchange.com/a/119587/171268 answer solved the issue don't know if it is correct way though. – abdul qayyum Oct 2 '18 at 8:24
  • You can always use standalone class for the tikzpictures and \includegraphics the results (assuming no conflict with graphicx). – John Kormylo Oct 2 '18 at 15:32
  • You can put the tikzpicture into a savebox. The figure will use the box immediately, even if it doesn't print until later. – John Kormylo Oct 2 '18 at 20:17
1

as you find yourself, problem is in document class aitthesis. you have two options:

  • consider JLDiaz answer on question (to which your question is duplicate)
  • check if the following solution works for you:

    \documentclass{report}
    \usepackage{capt-of}    % new
    \usepackage{tikz}
    
    \begin{document}
        \begin{center}
    \tikzset{
    neuron missing/.style = {scale=4, text depth=1.5ex, inner sep=0pt,
                             execute at begin node=$\vdots$
                            },
              circ/.style = {circle, fill=#1, minimum size = 1cm},
    every label/.append style = {label distance = 0pt, inner sep=2pt, font=\small}
            }
    
    \begin{tikzpicture}[x=1.6cm, y=1.6cm, >=stealth]
    
    \foreach \m/\n in {1/1,2,3,4,5/256}
    {
    \ifnum\m=4
        \node [neuron missing] (input-\m) at (0,2.5-\m) {};
    \else
        \node [circ=green!50]  (input-\m) at (0,2.5-\m) {};
        \draw [<-] (input-\m.west) -- node [above] {$I_{\n}$} + (-1,0);
    \fi
    }
    \foreach \m/\n in {1,2,3,4/16}
    {
    \ifnum\m=3
        \node [neuron missing]  (hiden-\m)  at (2,2-\m) {};
        \node [neuron missing]  (output-\m) at (4,2-\m) {};
    \else
        \node [circ=red!50,
               label=$H_{\n}$]  (hiden-\m)  at (2,2-\m) {};
        \node [circ=blue!50]    (output-\m) at (4,2-\m) {};
        \draw [->] (output-\m.east) -- node [above] {$O_{\n}$} + (1,0);
    \fi
    }
    \foreach \m in {1,2,3,5}
    \foreach \n in {1,2,4}
    {
    \draw [->]  (input-\m) -- (hiden-\n);
    }
    \foreach \m in {1,2,4}
    \foreach \n in {1,2,4}
    {
    \draw [->]  (hiden-\m) edge (output-\n);
    }
    \end{tikzpicture}
        \captionof{figure}{Caption}
    \label{fig:my_label}
        \end{center}
    \end{document}
    

as you can see, image is center environment, i.e. it not float anymore. with this (i hope so) the malfunction of aitthesis document class will be avoided.

i also took liberty and rewrote your image code that it is now more concise and consistent. maybe you like the introduced changes in neural network.

1

I don't know if this will work with alt-thesis class, but give it a shot.

\documentclass{article}
 \usepackage{tikz}
 \usetikzlibrary{positioning}

 \newsavebox{\tempbox}

 \begin{document}

\tikzset{%
neuron missing/.style={
draw=none, 
scale=4,
text height=0.333cm,
execute at begin node=\color{black}$\vdots$
},
}

\savebox{\tempbox}{\begin{tikzpicture}[x=1.5cm, y=1.5cm, >=stealth]

\foreach \m/\l [count=\y] in {1,2,3}
{
\node [circle,fill=green!50,minimum size=1cm] (input-\m) at (0,2.5-\y) {};
}
\foreach \m/\l [count=\y] in {4}
{
 \node [circle,fill=green!50,minimum size=1cm ] (input-\m) at (0,-2.5) {};
}

\node [neuron missing]  at (0,-1.5) {};


\foreach \m [count=\y] in {1}
\node [circle,fill=red!50,minimum size=1cm ] (hidden-\m) at (2,0.75) {};

\foreach \m [count=\y] in {2}
\node [circle,fill=red!50,minimum size=1cm ] (hidden-\m) at (2,-1.85) {};

\node [neuron missing]  at (2,-0.3) {};


\foreach \m [count=\y] in {1}
 \node [circle,fill=blue!50,minimum size=1cm ] (output-\m) at (4,1.5-\y) {};

\foreach \m [count=\y] in {2}
 \node [circle,fill=blue!50,minimum size=1cm ] (output-\m) at (4,-0.5-\y) {};

\node [neuron missing]  at (4,-0.4) {};

\foreach \l [count=\i] in {1,2,3,256}
 \draw [<-] (input-\i) -- ++(-1,0)
 node [above, midway] {$I_{\l}$};

\foreach \l [count=\i] in {1,16}
\node [above] at (hidden-\i.north) {$H_{\l}$};

\foreach \l [count=\i] in {1,16}
\draw [->] (output-\i) -- ++(1,0)
node [above, midway] {$O_{ \l}$};

\foreach \i in {1,...,4}
\foreach \j in {1,...,2}
\draw [->] (input-\i) -- (hidden-\j);

\foreach \i in {1,...,2}
\foreach \j in {1,...,2}
\draw [->] (hidden-\i) -- (output-\j);

 %\foreach \l [count=\x from 0] in {Input, Hidden, Ouput}
 % \node [align=center, above] at (\x*2,2) {\l \\ layer};

\end{tikzpicture}}

\begin{figure}
\centering
\usebox{\tempbox}
\caption{Caption}
\label{fig:my_label}
\end{figure}

\end{document} 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.