在下面的代码中,algorithm2e
--package 的选项 [italianokw] 不起作用。为什么?(我是这个包的新手。)
\documentclass{article}
\usepackage[italian]{babel}
\usepackage[utf8]{inputenc}
\usepackage[a4paper,top=3cm,bottom=3cm,left=1.5cm,right=1.5cm]{geometry}
\usepackage[italianokw,linesnumbered,lined,boxruled,commentsnumbered]{algorithm2e}
\begin{document}
\SetAlFnt{\Large}
\begin{algorithm}
\caption{Somma unaria}\label{alg:Somma unaria}
\SetAlgoLined
\SetKwProg{Fn}{Funzione}{}{}
\Fn{int piu(int $n$, int $m$)}{return $m+n$.\;}
\SetKwProg{Def}{def}{:}{}
\SetKwFor{While}{while}{:}{}
\Def{piu($m,n$)}{\While{$n!=0$}{$m,n=m+1,n-1$\\\textbf{return} $m$.}}
\end{algorithm}
\end{document}
第一次编辑:更准确地说,我想在标题中添加(可能使用更大的字体)算法 1。苏玛乌纳里。
太感谢了
答案1
您可以使用italiano
选项更改所有内容,而不仅仅是关键字。这将调整标题的名称:
\documentclass{article}
\usepackage[italian]{babel}
\usepackage[utf8]{inputenc}
\usepackage[a4paper,top=3cm,bottom=3cm,left=1.5cm,right=1.5cm]{geometry}
\usepackage[italiano,linesnumbered,lined,boxruled,commentsnumbered]{algorithm2e}
\begin{document}
\def\AlCapFnt{\Large}
\def\AlCapNameFnt{\Large}
\SetAlFnt{\Large}
\begin{algorithm}
\caption{Somma unaria}\label{alg:Somma unaria}
\SetAlgoLined
\SetKwProg{Fn}{Funzione}{}{}
\Fn{int piu(int $n$, int $m$)}{return $m+n$.\;}
\SetKwProg{Def}{def}{:}{}
\SetKwFor{While}{while}{:}{}
\Def{piu($m,n$)}{\While{$n!=0$}{$m,n=m+1,n-1$\\\textbf{return} $m$.}}
\end{algorithm}
\end{document}
答案2
由于您正在使用babel
,我建议使用它的功能,而不是(未很好实现的)italiano
选项。
我还建议对数学排版方式进行一些改变,并避免使用那些可怕的斜括号。
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[italian]{babel}
\usepackage[
twocolumn,% <--- just to make a smaller picture
a4paper,
top=3cm,
bottom=3cm,
left=1.5cm,
right=1.5cm
]{geometry}
\usepackage[
italiano,
italianokw,
linesnumbered,
lined,
boxruled,
commentsnumbered
]{algorithm2e}
\setlocalecaption{italian}{listalgorithmcf}{Elenco degli Algoritmi}
\setlocalecaption{italian}{algorithmcf}{Algoritmo}
\setlocalecaption{italian}{algorithmcfline}{riga}
\setlocalecaption{italian}{@algocf@proc}{Procedura}
\setlocalecaption{italian}{@algocf@func}{funzione}
\NewDocumentCommand{\vartype}{m}{\ifmmode\mathrm{#1}\ \else\textup{#1}\fi}
%\SetAlFnt{\Large} % <---- No, please!
\begin{document}
\listofalgorithms
\begin{algorithm}
\caption{Somma unaria}\label{alg:Somma unaria}
\SetAlgoLined
\SetKwProg{Fn}{Funzione}{}{}
\Fn{\vartype{int} $\mathit{piu}(\vartype{int} n, \vartype{int} m)$}{return $m+n$.\;}
\SetKwProg{Def}{def}{:}{}
\SetKwFor{While}{while}{:}{}
\Def{$\mathit{piu}(m,n)$}{\While{$n!=0$}{$m,n=m+1,n-1$\\\textbf{return} $m$.}}
\end{algorithm}
\end{document}