beamer
我正在尝试用法语准备一份演示文稿(使用该babel
包)。在我的演示文稿中有一个使用该pgfplots
包生成的直方图。这是我的代码:
\documentclass{beamer}
\usepackage[french]{babel}
\uselanguage{French}
\languagepath{French}
\usepackage{ragged2e,amsmath,booktabs,pgfplots}
\pgfplotsset{compat=1.7}
\usetheme{Madrid}
\usecolortheme{dove}
\setbeamercolor{background canvas}{bg=white}
\title{Lois de probabilité}
\author{Sa\"{i}d Maanan}
\institute{ISPITSG}
\date{}
\begin{document}
\begin{frame}
\titlepage
\end{frame}
\begin{frame}{Loi Binomiale}
\[
P\left(X=k\right) = \binom{n}{k} \cdot p^k \cdot q^{n-k}
\]
\end{frame}
\begin{frame}{Loi Binomiale}
\begin{example}
La probabilité qu'une certaine machine valide un test de durabilité est de $3/4$. Trouvez la probabilité que 2 des 4 prochaines machines valident le test ?
\end{example}
\pause
En supposant que les tests sont indépendants et $p = 3/4$ pour chacun des 4 tests, on obtient :
\pause
\begin{equation*}
\begin{split}
P(X=2)&=\binom{4}{2}\cdot\left(\frac{3}{4}\right)^2\cdot\left(\frac{1}{4}\right)^{2}\\
&=\left(\frac{4!}{2!2!}\right)\cdot\frac{9}{16}\cdot\frac{1}{16}\\
&=\frac{27}{128}\approx0.21
\end{split}
\end{equation*}
\end{frame}
\begin{frame}{Loi Binomiale}
\begin{example}
La probabilité qu'un patient se rétablisse d'une maladie sanguine rare est de 0.4. Si 15 personnes ont contracté cette maladie, quelle est la probabilité que :
\end{example}
\pause
\begin{enumerate}
\item au moins 10 survivent ?
\item 3 à 8 survivent ?
\item exactement 5 survivent ?
\end{enumerate}
\end{frame}
\begin{frame}{Loi Binomiale}
\begin{tikzpicture}[
declare function={binom(\k,\n,\p)=\n!/(\k!*(\n-\k)!)*\p^\k*(1-\p)^(\n-\k);}
]
\begin{axis}[
samples at={0,...,15},
yticklabel style={
/pgf/number format/fixed,
/pgf/number format/fixed zerofill,
/pgf/number format/precision=1
},
ybar=0pt, bar width=1
]
\addplot [fill=cyan, fill opacity=0.5] {binom(x,15,0.4)}; \addlegendentry{$p=0.4$}
\end{axis}
\end{tikzpicture}
\end{frame}
\begin{frame}{Loi de Poisson}
\[
P\left(X=k\right) = e^{-\lambda}\cdot\frac{\lambda^k}{k!}
\]
\end{frame}
\begin{frame}{Loi Normale}
\[
f(x) = \frac{1}{\sigma \sqrt{2\pi} } e^{-\frac{1}{2}\left(\frac{x-\mu}{\sigma}\right)^2}
\]
\end{frame}
\begin{frame}{Loi de $t$ de Student}
\[
f(t) = \frac{\Gamma\left(\frac{v+1}{2}\right)}{\sqrt{v\pi} \cdot \Gamma\left(\frac{v}{2}\right)} \cdot \left(1 + \frac{t^2}{v}\right)^{-\frac{v+1}{2}}
\]
\end{frame}
\end{document}
但每当我运行代码时都会出现这个错误:
! Paragraph ended before \pgfmath@local@@functions was complete.
那么这个错误意味着什么以及我该如何克服它?
编辑:提供的解决方案这里不适合我的问题。
答案1
如果你的演示文稿中不需要 babel 简写,你可以通过使用shorthands=off
包选项切换它们来避免错误:
\documentclass{beamer}
\usepackage[french,shorthands=off]{babel}
\uselanguage{French}
\languagepath{French}
\usepackage{ragged2e,amsmath,booktabs,pgfplots}
\pgfplotsset{compat=1.7}
\usetheme{Madrid}
\usecolortheme{dove}
\setbeamercolor{background canvas}{bg=white}
\title{Lois de probabilité}
\author{Sa\"{i}d Maanan}
\institute{ISPITSG}
\date{}
\begin{document}
\begin{frame}[fragile]
\frametitle{Loi Binomiale}
\begin{tikzpicture}[
declare function={binom(\k,\n,\p)=\n!/(\k!*(\n-\k)!)*\p^\k*(1-\p)^(\n-\k);}
]
\begin{axis}[
samples at={0,...,15},
yticklabel style={
/pgf/number format/fixed,
/pgf/number format/fixed zerofill,
/pgf/number format/precision=1
},
ybar=0pt, bar width=1
]
\addplot [fill=cyan, fill opacity=0.5] {binom(x,15,0.4)}; \addlegendentry{$p=0.4$}
\end{axis}
\end{tikzpicture}
\end{frame}
\end{document}
如果您在演示文稿的其他地方使用速记,则可以在本地将其关闭(在这种情况下,也可以使用fragile
框架选项):
\documentclass{beamer}
\usepackage[french]{babel}
\uselanguage{French}
\languagepath{French}
\usepackage{ragged2e,amsmath,booktabs,pgfplots}
\pgfplotsset{compat=1.7}
\usetheme{Madrid}
\usecolortheme{dove}
\setbeamercolor{background canvas}{bg=white}
\title{Lois de probabilité}
\author{Sa\"{i}d Maanan}
\institute{ISPITSG}
\date{}
\begin{document}
\begin{frame}[fragile]
\frametitle{Loi Binomiale}
\shorthandoff{:;?!}
\begin{tikzpicture}[
declare function={binom(\k,\n,\p)=\n!/(\k!*(\n-\k)!)*\p^\k*(1-\p)^(\n-\k);}
]
\begin{axis}[
samples at={0,...,15},
yticklabel style={
/pgf/number format/fixed,
/pgf/number format/fixed zerofill,
/pgf/number format/precision=1
},
ybar=0pt, bar width=1
]
\addplot [fill=cyan, fill opacity=0.5] {binom(x,15,0.4)}; \addlegendentry{$p=0.4$}
\end{axis}
\end{tikzpicture}
\end{frame}
\end{document}
作为第三种选择,您可以加载babel
TikZ 库(在这种情况下您还需要fragile
框架选项):
\documentclass{beamer}
\usepackage[french]{babel}
\uselanguage{French}
\languagepath{French}
\usepackage{ragged2e,amsmath,booktabs,pgfplots}
\pgfplotsset{compat=1.7}
\usetheme{Madrid}
\usecolortheme{dove}
\setbeamercolor{background canvas}{bg=white}
\title{Lois de probabilité}
\author{Sa\"{i}d Maanan}
\institute{ISPITSG}
\date{}
\usetikzlibrary{babel}
\begin{document}
\begin{frame}[fragile]
\frametitle{Loi Binomiale}
\begin{tikzpicture}[
declare function={binom(\k,\n,\p)=\n!/(\k!*(\n-\k)!)*\p^\k*(1-\p)^(\n-\k);}
]
\begin{axis}[
samples at={0,...,15},
yticklabel style={
/pgf/number format/fixed,
/pgf/number format/fixed zerofill,
/pgf/number format/precision=1
},
ybar=0pt, bar width=1
]
\addplot [fill=cyan, fill opacity=0.5] {binom(x,15,0.4)}; \addlegendentry{$p=0.4$}
\end{axis}
\end{tikzpicture}
\end{frame}
\end{document}