我的算法有问题,我正在使用 mcode 包:例如,我希望标题显示算法 1.1。如果我在图形环境中尝试它,它不起作用,因为我没有分页符,而我的算法很长。因此,我谷歌了一下,并想出了这个解决方案:
\documentclass[german,11pt,twoside,a4paper,final,titlepage,openany]{amsbook}
\usepackage[ngerman]{babel}
\usepackage[latin1]{inputenc}
\usepackage[pdftex]{graphicx}
\usepackage{mathrsfs,amssymb}
\usepackage{amsbsy,amsmath}
\usepackage{float}
\usepackage{subcaption}
\usepackage[framed,numbered]{mcode}
\begin{document}
\begin{lstlisting}
function y = PolyValMatrix(p,x)
y = zeros(size(p,1),size(x,1));
xt = x';
for i = 1:size(p,2)
n = size(p,2)-i;
y = y + p(:,i)*(xt.^n);
end
end
\end{lstlisting}
\renewcommand*\figurename{Algorithmus}
\captionof{figure}{Algorithmus}\label{algo:875}
\end{document}
但问题是:一旦我在此之后插入另一个图形,它也会将其称为 Algorithmus,而不是我希望的 Abbildung(图形)。
有人能帮帮我吗?抱歉,我用的是德语 :)
编辑:这个运行正确:
\documentclass[german,11pt,twoside,a4paper,final,titlepage,openany]{amsbook}
\usepackage[ngerman]{babel}
\usepackage[latin1]{inputenc}
\usepackage{graphicx} %% don't use [pdftex]
\usepackage{mathrsfs,amssymb}
\usepackage{amsbsy,amsmath}
\usepackage{float}
%\usepackage{subcaption}
\usepackage[framed,numbered]{mcode}
\addto\captionsngerman{\renewcommand\lstlistingname{Algorithmus}} %% Use this since
%% you are using babel
\begin{document}
\begin{lstlisting}[float=htb,
caption={Algorithmus\label{algo:875}},
%captionpos=b %% if you want caption below
]
function y = PolyValMatrix(p,x)
y = zeros(size(p,1),size(x,1));
xt = x';
for i = 1:size(p,2)
n = size(p,2)-i;
y = y + p(:,i)*(xt.^n);
end
end
\end{lstlisting}
Here we refer~\ref{algo:875}
\end{document}
而这个不是,但在我看来,除了不使用浮点数外,它是完全相同的(但这没有什么区别......)
\documentclass[german,11pt,twoside,a4paper,final,titlepage,openany]{amsbook}
\usepackage[ngerman]{babel}
\usepackage[latin1]{inputenc}
\usepackage{graphicx}
\usepackage{mathrsfs,amssymb}
\usepackage{amsbsy,amsmath}
\usepackage{float}
%\usepackage{subcaption}
\usepackage[framed,numbered]{mcode}
\addto\captionsngerman{\renewcommand\lstlistingname{Algorithmus}} %% Use this since
\begin{document}
Here we refer ~\ref{algo:875}
\begin{lstlisting}[%float=htb,
caption={Algorithmus\label{algo:875}},
captionpos=b %% if you want caption below
]
%Benötigte Funktionen
function y = PolyValMatrix(p,x)
y = zeros(size(p,1),size(x,1));
xt = x';
for i = 1:size(p,2)
n = size(p,2)-i;
y = y + p(:,i)*(xt.^n);
end
end
\end{lstlisting}
Here we refer ~\ref{algo:875}
\end{document}
答案1
mcode
内部用于listings
排版 matlab 代码。因此,您可以使用其自身添加标题listings
。
\documentclass[german,11pt,twoside,a4paper,final,titlepage,openany]{amsbook}
\usepackage[ngerman]{babel}
\usepackage[latin1]{inputenc}
\usepackage{graphicx} %% don't use [pdftex]
\usepackage{mathrsfs,amssymb}
\usepackage{amsbsy,amsmath}
\usepackage{float}
%\usepackage{subcaption}
\usepackage[framed,numbered]{mcode}
\addto\captionsngerman{\renewcommand\lstlistingname{Algorithmus}} %% Use this since
%% you are using babel
\begin{document}
\begin{lstlisting}[float=htb,
caption={Algorithmus},
label={algo:875},
%captionpos=b %% if you want caption below
]
function y = PolyValMatrix(p,x)
y = zeros(size(p,1),size(x,1));
xt = x';
for i = 1:size(p,2)
n = size(p,2)-i;
y = y + p(:,i)*(xt.^n);
end
end
\end{lstlisting}
Here we refer~\ref{algo:875}
\end{document}