Beamer里如何用演算法環境?
是這樣的,在article類裡面用是沒有問題的,但是一旦放到beamer里,就會報錯,這是為什麼呢?
% !TeX encoding = UTF-8
% !TEX program = xelatex
documentclass[notheorems,handout]{beamer}
usepackage{latexsym}
usepackage{amsmath,amssymb,bm}
usepackage{color,xcolor,tikz}
usepackage{graphicx}
usepackage{algorithm,algorithmic}
usepackage{amsthm}
usepackage{xeCJK}
setCJKmainfont{SimSun}
usepackage{hyperref}
hypersetup{hidelinks}
mode&
{
usetheme{Madrid}
usetheme{Dresden}
%setbeamercovered{transparent}
usefonttheme[onlymath]{serif}
usecolortheme{whale}
}ewtheorem{proposition}{命題}
ewtheorem{theorem}{定理}
ewtheorem{definition}{定義}
ewtheorem{example}{例}
enewcommandfigurename{圖}
enewcommand ablename{表}
setbeamertemplate{theorems}[numbered]
egin{document}
egin{frame}
egin{algorithm} % enter the algorithm environment
caption{Calculate $y = x^n$} % give the algorithm a caption
label{alg1} % and a label for
ef{} commands later in the document
egin{algorithmic} % enter the algorithmic environment
REQUIRE $n geq 0 vee x
eq 0$
ENSURE $y = x^n$
STATE $y Leftarrow 1$
IF{$n &< 0$} STATE $X Leftarrow 1 / x$ STATE $N Leftarrow -n$ ELSE STATE $X Leftarrow x$ STATE $N Leftarrow n$ ENDIF WHILE{$N eq 0$} IF{$N$ is even} STATE $X Leftarrow X imes X$ STATE $N Leftarrow N / 2$ ELSE[$N$ is odd] STATE $y Leftarrow y imes X$ STATE $N Leftarrow N - 1$ ENDIF ENDWHILE end{algorithmic} end{algorithm} end{frame} end{document}
卸腰。
Beamer and pseudocode
雖然知乎越來越水,咱們還是先搜一下再問吧……簡單說就是偽代碼這個環境(其實我沒有用過)是個浮動體,然後呢,用float包然後浮動體位置是H就好啦。enewcommandfigurename{圖} enewcommand ablename{表}% !TeX encoding = UTF-8
% !TEX program = xelatex
documentclass[notheorems,handout]{beamer}
usepackage{latexsym}
usepackage{amsmath,amssymb,bm}
usepackage{color,xcolor,tikz}
usepackage{graphicx}
usepackage{algorithm,algorithmic}
usepackage{amsthm}
%usepackage{xeCJK}
%setCJKmainfont{SimSun}
usepackage{hyperref}
hypersetup{hidelinks}
mode&
{
usetheme{Madrid}
usetheme{Dresden}
%setbeamercovered{transparent}
usefonttheme[onlymath]{serif}
usecolortheme{whale}
}
usepackage{float} %HERE!!!!!!!!!!!!!!
%
ewtheorem{proposition}{命題}
%
ewtheorem{theorem}{定理}
%
ewtheorem{definition}{定義}
%
ewtheorem{example}{例}
setbeamertemplate{theorems}[numbered]
egin{document}
egin{frame}
egin{algorithm}[H] % HERE!!!!!!!!!
caption{Calculate $y = x^n$} % give the algorithm a caption
label{alg1} % and a label for
ef{} commands later in the document
egin{algorithmic} % enter the algorithmic environment
REQUIRE $n geq 0 vee x
eq 0$
ENSURE $y = x^n$
STATE $y Leftarrow 1$
IF{$n &< 0$}
STATE $X Leftarrow 1 / x$
STATE $N Leftarrow -n$
ELSE
STATE $X Leftarrow x$
STATE $N Leftarrow n$
ENDIF
WHILE{$N
eq 0$}
IF{$N$ is even}
STATE $X Leftarrow X imes X$
STATE $N Leftarrow N / 2$
ELSE[$N$ is odd]
STATE $y Leftarrow y imes X$
STATE $N Leftarrow N - 1$
ENDIF
ENDWHILE
end{algorithmic}
end{algorithm}
end{frame}
end{document}
原來問題在於[H],這個選項
推薦閱讀:
※LaTeX到底怎麼加bib??
※蘋果公司為何用基於 XSL-FO 的 XEP 來生成《iOS Human Interface Guidelines》等文檔的 PDF 版本?相較 TeX 解決方案及 InDesign 等軟體,它有何優勢?
※有什麼好的鍛煉自己 LaTeX 能力的方法?
※如何提高使用 LaTeX 的水平?
※如何定義一個LaTeX行內代碼環境?
TAG:LaTeX | TeX | LaTeX排版與設計 |
