![tikz 包不适用于大学论文课程,AIT](https://linux22.com/image/383596/tikz%20%E5%8C%85%E4%B8%8D%E9%80%82%E7%94%A8%E4%BA%8E%E5%A4%A7%E5%AD%A6%E8%AE%BA%E6%96%87%E8%AF%BE%E7%A8%8B%EF%BC%8CAIT.png)
我正在使用ait-thesis
模板,当我将一个包裹tikz picture
在里面时,它会出现错误figure
。我尝试添加删除包,发现与以下链接\usepackage{tikz}
冲突aitthesis.cls
班级。如果我将 tikz 包放在它前面,则不会出现问题,但其余文档全都乱了。真正的错误是too many }s, Latex Error: \begin{document} end with \end{figure}
。错误文件显示:\color@endbox ->\color@endgroup \egroup
。你能解决它吗?我的代码在独立文档类中工作。没有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}
答案1
正如您所发现的,问题出在文档类中aitthesis
。您有两个选择:
- 考虑杰利迪亚兹回答问题(你的问题与之重复)
检查以下解决方案是否适合您:
\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}
正如您所见,图像是center
环境,即它不再浮动。这样(我希望如此)aitthesis
就可以避免文档类的故障。
我还擅自重写了你的图像代码,使其现在更加简洁和一致。也许你喜欢神经网络中引入的变化。
答案2
我不知道这是否适用于 alt-thesis 课程,但可以尝试一下。
\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}