我对 Latex 还不熟悉,在将 MATLAB 中的图形居中时遇到了一些困难。如您所见,MATLAB 中的代码在 Latex 上打印得很完美,图片也是如此。但是,我使用了,\centering
但\begin{center}
没有成功。
\documentclass[12pt]{article}%For type of paper
\usepackage{authblk}%For author commands
\usepackage{setspace}% For double space
\doublespacing% For double space
\usepackage{subeqnarray} % For number equations (1a), (1b) etc.
\usepackage{graphicx,epstopdf} % For including graphics
\usepackage[framed , numbered]{matlab-prettifier}% For MATLAB code
\usepackage{amssymb}% For ams math, symbol packages
\usepackage{amsmath} % For more ams
\usepackage{nccmath}% For adding Mathematical commands
\usepackage[english]{babel}
\usepackage{blindtext}
\usepackage[a4paper,margin=2.5cm]{geometry} % set page margins as needed
\newcommand{\diff}{\mathop{}\!d}
\begin{document}
\begin{figure}[h]
\includegraphics[width=1.50\textwidth]{fourierSeries.eps}
\centering
\end{figure}
\lstinputlisting[style = Matlab-editor]{fourierSeries.m}
\end{document}
以下是来自 MATLAB 的代码:
function [ao,a,b] = fourierSeries(f,T,N)
syms t;
T = 2;
wo = 2*pi/T;
% heaviside(x-k) when k = 1, heaviside(x-1). it shifts the graph to the right.
% when k = -1, for example, the graph is shift to the left.
f = heaviside(t) - heaviside(t-1);
ao_sym = 1/T* int(f,t,0,T);
ao = double(ao_sym);
for n = 1:N;
a_sym(n) = 2/T*int(f*cos(n*wo*t),t,0,T);
b_sym(n) = 2/T*int(f*sin(n*wo*t),t,0,T);
a(n) = double(a_sym(n));
b(n) = double(b_sym(n));
end
end