1. 程式人生 > >latex下IEEE模板中巢狀Python程式碼

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}