前言
本文总结了一些网上的例子。
1.代码
注意代码要顶格复制
\usepackage{listings}
\usepackage{xcolor}
\setmonofont{Consolas}
\definecolor{grey}{rgb}{0.8,0.8,0.8}
\definecolor{darkgreen}{rgb}{0,0.3,0}
\definecolor{darkblue}{rgb}{0,0,0.7}
\lstset{%
numbers=left,
numberstyle=\small,%
showstringspaces=false,
showspaces=false,%
tabsize=4,%
frame=lines,%
basicstyle=\ttfamily,%
keywordstyle=\bfseries\color{darkblue},%
%identifierstyle=,%
commentstyle=\color{darkgreen},%\itshape,%
stringstyle=\color{black},%
language=c
}
效果:
我很喜欢的一款,陪伴了我一个学期的。
\usepackage{listings}
\usepackage{xcolor}
\setmonofont{Consolas}
\definecolor{mygreen}{rgb}{0,0.6,0}
\definecolor{mygray}{rgb}{0.5,0.5,0.5}
\definecolor{mymauve}{rgb}{0.58,0,0.82}
\linespread{1.5}%行距调整
\lstset{
backgroundcolor=\color{white}, % choose the background color
basicstyle=\ttfamily\footnotesize, % size of fonts used for the code或改成\small\monaco稍大
numbers=left, % 设置行号
numberstyle=\footnotesize, % 设置行号字体大小
columns=fullflexible,
breaklines=true, % automatic line breaking only at whitespace
captionpos=b, % sets the caption-position to bottom
tabsize=4, % 把tab扩展为4个空格,默认是8个太长
commentstyle=\color{mygreen}, % 设置注释颜色
keywordstyle=\bfseries\color{blue}, % 设置keyword颜色
stringstyle=\color{mymauve}, % string literal style
frame=single, % 设置有边框
rulesepcolor=\color{red!20!green!20!blue!20},
identifierstyle=\color{black},
language = c,
}
一个网上的高赞设置:
\usepackage{graphicx}
\usepackage{xcolor}
\usepackage{listings}
\lstset{%
%alsolanguage=Java,
language={C++}, %language为,还有{[Visual]C++}
%alsolanguage=[ANSI]C, %可以添加很多个alsolanguage,如alsolanguage=matlab,alsolanguage=VHDL等
%alsolanguage= tcl,
%alsolanguage= XML,
tabsize=4, %
frame=shadowbox, %把代码用带有阴影的框圈起来
commentstyle=\color{red!50!green!50!blue!50},%浅灰色的注释
rulesepcolor=\color{red!20!green!20!blue!20},%代码块边框为淡青色
keywordstyle=\color{blue!90}\bfseries, %代码关键字的颜色为蓝色,粗体
showstringspaces=false,%不显示代码字符串中间的空格标记
stringstyle=\ttfamily, % 代码字符串的特殊格式
keepspaces=true, %
breakindent=22pt, %
numbers=left,%左侧显示行号 往左靠,还可以为right,或none,即不加行号
stepnumber=1,%若设置为2,则显示行号为1,3,5,即stepnumber为公差,默认stepnumber=1
%numberstyle=\tiny, %行号字体用小号
numberstyle={\color[RGB]{0,192,192}\tiny} ,%设置行号的大小,大小有tiny,scriptsize,footnotesize,small,normalsize,large等
numbersep=8pt, %设置行号与代码的距离,默认是5pt
basicstyle=\footnotesize, % 这句设置代码的大小
showspaces=false, %
flexiblecolumns=true, %
breaklines=true, %对过长的代码自动换行
breakautoindent=true,%
breakindent=4em, %
aboveskip=1em, %代码块边框
tabsize=2,
showstringspaces=false, %不显示字符串中的空格
backgroundcolor=\color[RGB]{245,245,244}, %代码背景色
%backgroundcolor=\color[rgb]{0.91,0.91,0.91} %添加背景色
escapeinside=``, %在``里显示中文
%% added by http://bbs.ctex.org/viewthread.php?tid=53451
fontadjust,
captionpos=t,
framextopmargin=2pt,framexbottommargin=2pt,abovecaptionskip=-3pt,belowcaptionskip=3pt,
xleftmargin=4em,xrightmargin=4em, % 设定listing左右的空白
texcl=true,
% 设定中文冲突,断行,列模式,数学环境输入,listing数字的样式
extendedchars=false,columns=flexible,mathescape=true
% numbersep=-1em
}
效果:
2.latex绘制matlab图
1.在matlab下画完图以后写入
print(gcf, '-depsc', '**.eps')
2.将eps文件做为图片直接插入,需要引入宏包;
\usepackage{graphicx}
3.matlab绘图
地理气泡图
方法1:
lat = [ 30, 34, 56];%纬度
lon = [120,115,118];%经度
v1 = [ 22, 34, 56];%气泡大小
v2 = [cellstr('北京'),cellstr('上海'),cellstr('杭州')];%分类依据
v2 = categorical(v2);%转化数据结构
geobubble(lat,lon,v1,v2);
geobubble的四个参数依次是:纬度,经度,气泡的大小,分类的依据。
其中分类的依据需要转化为categorical结构。
效果:
杭州的位置好像有问题,不是很清楚。
方法2:数据表绘图
首先准备一张表,内容是每列分别为:经度,纬度,气泡大小,分类依据
a = readtable('1.xlsx','VariableNamingRule','preserve');%读取数据表,并且指定列的名称不变
a.v2= categorical(a.v2);%分类依据转化结构
geobubble(a,'lon','lat','SizeVariable','v1','ColorVariable','v2');%绘图
注意读表必须写出对应的参数名,参数值。而前一种直接画图不能写出参数名,直接带值。(不然会报错,这个不是很懂)。
效果:
添加标题:
gb = geobubble(a,'lon','lat','SizeVariable','v1','ColorVariable','v2');
gb.SizeLegendTitle = 'Max Height';
gb.ColorLegendTitle = 'Cause';
gb.Title = 'Table';
matlab可以画很多好看的图,大家不要再画那种丑丑的图了。
https://ww2.mathworks.cn/help/matlab/creating_plots/types-of-matlab-plots.html
Latex绘制流程图
reference
1.Southan97:在LaTeX中优雅地插入代码,并使用Consolas字体!
3.闭上哟臭嘴202:请教各位大侠,我用matlab生成的三维图是彩色的,但生成的eps却是黑白的,是怎么回事谢谢了,大神帮忙啊