在latex中嵌套java 代码
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{inconsolata}
\usepackage{ctex}
\usepackage{color}
\definecolor{pblue}{rgb}{0.13,0.13,1}
\definecolor{pgreen}{rgb}{0,0.5,0}
\definecolor{pred}{rgb}{0.9,0,0}
\definecolor{pgrey}{rgb}{0.46,0.45,0.48}
\definecolor{gray}{rgb}{0.5,0.5,0.5}
\usepackage{listings}
\lstset{
backgroundcolor=\color{green}, % 选择代码背景,必须加上\ usepackage {color}或\ usepackage {xcolor}.
frame=single,
rulecolor=\color{red},
language=Java,
aboveskip=3mm,
belowskip=3mm,
showspaces=false,
showtabs=false,
columns=flexible,
breaklines=true,
tabsize=2,
numbers=left,
numbersep=-5pt,
numberstyle=\tiny\color{red},
showstringspaces=false,
breakatwhitespace=true,%设置是否当且仅当在空白处自动中断.
commentstyle=\color{pgreen},
keywordstyle=\color{pblue},
stringstyle=\color{pred},
basicstyle=\ttfamily,% 设置代码字号.
moredelim=[il][\textcolor{pgrey}]{$$},
moredelim=[is][\textcolor{pgrey}]{\%\%}{\%\%}
}
\begin{document}
\section{抽象产品}
\begin{lstlisting}
package com.china.shanghai.wanson;
public abstract class Product {
public abstract void show();
}
\end{lstlisting}
\section{具体产品}
\begin{lstlisting}
package com.china.shanghai.wanson;
public class ConcreteProduct1 extends Product {
@Override
public void show() {
System.out.println("产品1");
}
}
package com.china.shanghai.wanson;
public class ConcreteProduct2 extends Product {
@Override
public void show() {
System.out.println("产品2");
}
}
\end{lstlisting}
\begin{lstlisting}
\end{lstlisting}
\end{document}
posted on 2020-07-13 13:23 Indian_Mysore 阅读(747) 评论(0) 收藏 举报
浙公网安备 33010602011771号