![将Matlab代码插入Latex的两种方法](https://linux22.com/image/432432/%E5%B0%86Matlab%E4%BB%A3%E7%A0%81%E6%8F%92%E5%85%A5Latex%E7%9A%84%E4%B8%A4%E7%A7%8D%E6%96%B9%E6%B3%95.png)
我有两种方法可以将 Matlab 代码插入 Latex。但它们都有一个缺点,我想改变它。首先,我展示我的代码和结果:
\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{geometry}
\geometry{a4paper,left=3cm,right=2.5cm,top=2.5cm,bottom=2.5cm}
\usepackage{sectsty}
\sectionfont{\fontsize{14}{14}\selectfont}
\subsectionfont{\fontsize{12}{12}\selectfont}
\usepackage{setspace}
\renewcommand{\baselinestretch}{1.5}
\usepackage{minted}
\usepackage{listings} %code extracts
\usepackage{xcolor} %custom colours
\usepackage{mdframed} %nice frames
\definecolor{light-gray}{gray}{0.95} %the shade of grey that stack exchange uses
\begin{document}
\noindent \textbf{Example using minted package}:
\definecolor{bg}{rgb}{0.95,0.95,0.95}
\begin{minted}[bgcolor=bg]{matlab}
A = [1 0; 2 4];
B = [5 9; 2 1];
if isequal(size(A),size(B))
C = A + B;
end
C
>>
C =
6 9
4 5
\end{minted}
\noindent \textbf{Example using mdframed package}:
\begin{mdframed}[backgroundcolor=light-gray, roundcorner=10pt,leftmargin=1, rightmargin=1, innerleftmargin=15, innertopmargin=15,innerbottommargin=15, outerlinewidth=1, linecolor=light-gray]
\begin{lstlisting}[language = matlab]
A = [1 0; 2 4];
B = [5 9; 2 1];
if isequal(size(A),size(B))
C = A + B;
end
C
>>
C =
6 9
4 5
\end{lstlisting}
\end{mdframed}
\end{document}
我想知道如何将 eg.1 的字体改为 eg.2,因为 eg.2 的字体更美观。或者如何将 eg.2 中的关键字颜色从黑色改为彩色?
我不知道该如何修复它们。请帮帮我。提前谢谢!