latex下IEEE模板中嵌套Python代码

如果想在LATEX中嵌套Python代码推荐使用listings

\usepackage[procnames]{listings}
然后在正文中使用
\lstset{language=Python, basicstyle=\ttfamily\small }
\begin{lstlisting}[frame=single]
mlp= MLPClassifier(solver=‘sgd’, alpha=1e-5,hidden_layer_sizes=(5, 5), random_state=1)
mlp.fit(X_train, y_train)
predicted=mlp.predict(X_test)
\end{lstlisting}

完整格式如下:

\documentclass[conference]{IEEEtran}
\usepackage[procnames]{listings}
\usepackage{CJKutf8}
\begin{document}
\begin{CJK*}{UTF8}{gbsn}
\definecolor{keywords}{RGB}{255,0,90}
\definecolor{comments}{RGB}{0,0,113}
\definecolor{red}{RGB}{160,0,0}
\definecolor{green}{RGB}{0,150,0}

\lstset{language=Python, 
        basicstyle=\ttfamily\small, 
        keywordstyle=\color{keywords},
        commentstyle=\color{comments},
        stringstyle=\color{red},
        showstringspaces=false,
        identifierstyle=\color{green},
        procnamekeys={def,class}
        }

\begin{lstlisting}[frame=single]
mlp= MLPClassifier(solver='sgd', alpha=1e-5
,hidden_layer_sizes=(5, 5), random_state=1)
mlp.fit(X_train, y_train)
predicted=mlp.predict(X_test)
\end{lstlisting}

\clearpage
\end{CJK*}
\end{document}

猜你喜欢

转载自blog.csdn.net/zhangpeterx/article/details/83217653
今日推荐