我正在尝试在 beamer 模板中使用 tikz 图形,但不幸的是我一直遇到错误:
LaTex Error : Environment axis undefined
这是用于绘制模板的代码:
% !TEX encoding = UTF-8 Unicode
\documentclass[french]{beamer}
\usepackage{hyperref}
\usepackage[utf8]{inputenc}
%\usepackage[T1]{fontenc}
\UseRawInputEncoding
\usepackage{pgfpages}
\usepackage{pgf, tikz, adjustbox}
\usetikzlibrary{arrows.meta,
patterns.meta
}
% other packages
\usepackage{latexsym,amsmath,xcolor,multicol,booktabs,calligra}
\usepackage{graphicx,listings,stackengine}
%% Enable only in Xelatex
% \usepackage{pstricks}
\author{XXX}
\title{Etalement à interface élastique}
\subtitle{Presentation}
\institute [Sorbonne Université - ESPCI, Paris] {Laboratoire \\PSL University}
\date{\today}
\usepackage{YTU}
% defs
\def\cmd#1{\texttt{\color{red}\footnotesize $\backslash$#1}}
\def\env#1{\texttt{\color{blue}\footnotesize #1}}
\definecolor{deepblue}{rgb}{0,0,0.5}
\definecolor{deepred}{rgb}{0.6,0,0}
\definecolor{deepgreen}{rgb}{0,0.5,0}
\definecolor{halfgray}{gray}{0.55}
\lstset{
basicstyle=\ttfamily\small,
keywordstyle=\bfseries\color{deepblue},
emphstyle=\ttfamily\color{deepred}, % Custom highlighting style
stringstyle=\color{deepgreen},
numbers=left,
numberstyle=\small\color{halfgray},
rulesepcolor=\color{red!20!green!20!blue!20},
frame=shadowbox,
}
\begin{document}
\begin{frame}
\titlepage
\begin{note}
{Introduce your self}
\end{note}
\end{frame}
% THIS IS THE FRAME OF CONCERN
\begin{frame}[fragile]
\begin{figure}[h]
\centering
\begin{tikzpicture}[dot/.style = {circle, fill, inner sep=1.0pt, node contents={}}]
\begin{axis}[
no markers, domain=0:14, samples=200,
axis lines=none, %axis lines*=left,
xlabel=$x$, ylabel=$y$,
every axis y label/.style={at=(current axis.above origin),anchor=south},
every axis x label/.style={at=(current axis.right of origin),anchor=west},
height=5cm, width=17cm,
xtick={\mean,12.5}, ytick=\empty,
enlargelimits=false, clip=false, axis on top,
grid = major
]
% On crée les 2 courbes gaussiennes en les nommant et en les remplissant
\addplot [fill=cyan!20, draw=none, domain=0:14] {gaussian(1.5+\std,\mean)} \closedcycle;
\addplot [name path=haute,very thick,cyan!50!black] {gaussian(1.5+\std, \mean)+0.05};
\addplot [name path=basse,very thick,cyan!50!black] {gaussian(1.5+\std, \mean)};
\addplot [very thick,cyan!50!black] {gaussian(1.5+\std, \mean)+0.05}--(14,0); % ligne entre fin de la fonction et axe des abscisses
% On remplit la zone entre les 2 courbes
\addplot fill between[
of = haute and basse,
soft clip={domain=0:14},
every even segment/.style = {pink,opacity=.2}
];
% On crée une ligne artificielle pour fermer le contour à gauche
\draw[very thick, cyan!50!black] (0,0) -- (0,0.05011524462);
% On crée les indications pour les quantités H(x,t) et R(x,t)
\draw[dashed,red, stealth-stealth, very thick] (8,0) -- node[fill=cyan!20,scale=0.75] {$h(x,t)$} (8,0.189940);
\draw[dashed,red, stealth-stealth, thick] (7,0.025) -- node[fill=cyan!20,scale=0.75] {$R(x,t)$} (12.5,0.025);
% On remplit la zone intermédiaire entre les 2 rectangles gris (SANS CONTOURS)
\path[fill=cyan!20] (6.25,-0.2) -- (6.25,0) -- (7.75,0) -- (7.75,-0.2) -- (6.25,-0.2);
% On crée artificiellement 2 contours qui nous intéressent
\draw[black] (6.25,-0.2) -- (6.25,0);
\draw[black] (7.75,-0.2) -- (7.75,0);
% On construit les rectangles de la base à la main
\draw[black, fill=gray!20] (0,-0.075) -- (0,0) -- (6.25,0) -- (6.25,-0.075) -- (0,-0.075);
\draw[black, fill=gray!20] (14,-0.075) -- (14,0) -- (7.75,0) -- (7.75,-0.075) -- (14,-0.075);
\draw[black, pattern = checkerboard] (0,-0.12) -- (0,-0.075) -- (6.25,-0.075) -- (6.25,-0.12) -- (0,-0.12);
\draw[black, pattern = checkerboard] (14,-0.12) -- (14,-0.075) -- (7.75,-0.075) -- (7.75,-0.12) -- (14,-0.12);
% On crée le label sur le flux Q(x,t)
\draw [yshift=-0.6cm, -stealth](7,-0.1) -- node [fill=cyan!20] {$Q(t)$} (7,0);
\node[right] at (5.5,0.1) {$(\rho,\mu)$};
% On crée les flèches pour les zones à labeliser à la main
\draw[black, stealth-, very thick] (9,0.13) -- node[pos = 0.8,below right,scale=1] {Elastic membrane} (12,0.25);
\draw[black, stealth-, very thick] (6,0.03) -- node[pos = 0.8,below left,scale=1] {Silicon oil} (3,0.25);
\draw[black, -stealth, very thick] (5,-0.2) -- node[pos = 0.2,above left,scale=1] {Checkerboard pattern} (5,-0.12);
%\draw [yshift=-0.6cm, latex-latex](axis cs:4,0) -- node [fill=white] {$Q(t)$} (axis cs:5.96,0);
% Construction des axes
\draw[dotted,-stealth,thick] (7, 0) -- (15, 0) node[right] {$\underline{e}_x$}; % x-axis
\draw[dotted,-stealth,thick] (7, 0) -- ( 7,0.325) node[above] {$\underline{e}_z$}; % y-axis
\path (7,0) node[black,dot,label=below left:$0$];
\end{axis}
\end{tikzpicture}
\end{figure}
\end{frame}
\end{document}
因为它是一个导入的模板,所以我使用了一个名为“YTU.sty”的附加文件,其中包含其他包:
\mode<presentation>
\newif\ifbeamer@secheader
\beamer@secheaderfalse
%\DeclareOptionBeamer{secheader}{\beamer@secheadertrue}
\ProcessOptionsBeamer
\useoutertheme[footline=authorinstitutetitle,subsection=false]{smoothbars}
\makeatletter % [add curpage/total page at the bottom](http://tex.stackexchange.com/questions/100838/beamer-dresden-theme-miniframes-appeareance-and-frame-number-insertion)
\newcommand{\frameofframes}{/}
\newcommand{\setframeofframes}[1]{\renewcommand{\frameofframes}{#1}}
\setbeamertemplate{footline}
{%
\begin{beamercolorbox}[colsep=1.5pt]{upper separation line foot}
\end{beamercolorbox}
\begin{beamercolorbox}[ht=2.5ex,dp=1.125ex,%
leftskip=.3cm,rightskip=.3cm plus1fil]{author in head/foot}%
\leavevmode{\usebeamerfont{author in head/foot}\insertshortauthor}%
\hfill%
{\usebeamerfont{institute in head/foot}\usebeamercolor[fg]{institute in head/foot}\insertshortinstitute}%
\end{beamercolorbox}%
\begin{beamercolorbox}[ht=2.5ex,dp=1.125ex,%
leftskip=.3cm,rightskip=.3cm plus1fil]{title in head/foot}%
{\usebeamerfont{title in head/foot}\insertshorttitle}%
\hfill%
{\usebeamerfont{frame number}\usebeamercolor[fg]{frame number}\insertframenumber~\frameofframes~\inserttotalframenumber}
\end{beamercolorbox}%
\begin{beamercolorbox}[colsep=1.5pt]{lower separation line foot}
\end{beamercolorbox}
}
\makeatother
\useinnertheme{circles}
%\useoutertheme{default}
%\useinnertheme[shadow=true]{rounded}
%define qut theme color
\xdefinecolor{qut}{HTML}{00407a} %PANTONE 541 BLUE
\setbeamercolor{footline}{bg=qut}
\setbeamercolor{frametitle}{bg=qut,fg=white}
\setbeamercolor{title}{bg=qut}
\setbeamerfont{frametitle}{size=\large}
%\setbeamertemplate{navigation symbols}{}
\setbeamertemplate{bibliography item}[text]
\setbeamertemplate{caption}[numbered]
\setbeamercolor{palette primary}{use=structure,fg=white,bg=structure.fg}
\setbeamercolor{palette secondary}{use=structure,fg=white,bg=structure.fg!75!black}
\setbeamercolor{palette tertiary}{use=structure,fg=white,bg=structure.fg!50!black}
\setbeamercolor{palette quaternary}{fg=white,bg=structure.fg!50!black}
%\setbeamercolor*{sidebar}{use=structure,bg=structure.fg}
\setbeamercolor{titlelike}{parent=palette primary}
%% try
\setbeamercolor{block title}{bg=qut}
\setbeamercolor*{block title example}{use={normal text,example text},bg=white,fg=qut}
\setbeamercolor{fine separation line}{}
\setbeamercolor{item projected}{fg=white}
\setbeamercolor{palette sidebar primary}{use=normal text,fg=normal text.fg}
\setbeamercolor{palette sidebar quaternary}{use=structure,fg=structure.fg}
\setbeamercolor{palette sidebar secondary}{use=structure,fg=structure.fg}
\setbeamercolor{palette sidebar tertiary}{use=normal text,fg=normal text.fg}
%\setbeamercolor{palette sidebar quaternary}{fg=white}
\setbeamercolor{section in sidebar}{fg=brown}
\setbeamercolor{section in sidebar shaded}{fg=grey}
\setbeamercolor{separation line}{}
\setbeamercolor{sidebar}{bg=qut}
\setbeamercolor{sidebar}{parent=palette primary}
\setbeamercolor{structure}{fg=qut}
\setbeamercolor{subsection in sidebar}{fg=brown}
\setbeamercolor{subsection in sidebar shaded}{fg=grey}
\AtBeginSection[]{
\begin{frame}
\tableofcontents[sectionstyle=show/shaded,subsectionstyle=show/shaded/hide,subsubsectionstyle=show/shaded/hide]
\end{frame}
}
\AtBeginSubsection[]{
\begin{frame}
\tableofcontents[sectionstyle=show/shaded,subsectionstyle=show/shaded/hide,subsubsectionstyle=show/shaded/hide]
\end{frame}
}
\mode
<all>
有人可以帮我解决这个问题吗(我是 beamer 的初学者)?
在此先感谢您的帮助,
答案1
几个问题:
你缺少
pgfplots
编译代码所需的软件包以及六个库。我建议你回到你获取此代码的地方,并复制其余的宏
\mean
且未\std
定义函数
gaussian
未定义丢失的
\pgfplotsset{compat=newest}
以下代码可以编译,但不一定能给出合理的输出。您必须调整我为缺失的宏和函数使用的虚拟定义,才能获得所需的结果
% !TEX encoding = UTF-8 Unicode
\documentclass[french]{beamer}
%\usepackage{hyperref}
\usepackage[utf8]{inputenc}
%\usepackage[T1]{fontenc}
%\UseRawInputEncoding
\usepackage{pgfpages}
\usepackage{pgf, tikz, adjustbox}
\usetikzlibrary{arrows.meta,
patterns.meta
}
% other packages
\usepackage{latexsym,
%,amsmath,xcolor,multicol,
booktabs,calligra}
\usepackage{
%graphicx,
listings,stackengine}
%% Enable only in Xelatex
% \usepackage{pstricks}
\author{XXX}
\title{Etalement à interface élastique}
\subtitle{Presentation}
\institute [Sorbonne Université - ESPCI, Paris] {Laboratoire \\PSL University}
\date{\today}
%\usepackage{YTU}
% defs
\def\cmd#1{\texttt{\color{red}\footnotesize $\backslash$#1}}
\def\env#1{\texttt{\color{blue}\footnotesize #1}}
\definecolor{deepblue}{rgb}{0,0,0.5}
\definecolor{deepred}{rgb}{0.6,0,0}
\definecolor{deepgreen}{rgb}{0,0.5,0}
\definecolor{halfgray}{gray}{0.55}
\lstset{
basicstyle=\ttfamily\small,
keywordstyle=\bfseries\color{deepblue},
emphstyle=\ttfamily\color{deepred}, % Custom highlighting style
stringstyle=\color{deepgreen},
numbers=left,
numberstyle=\small\color{halfgray},
rulesepcolor=\color{red!20!green!20!blue!20},
frame=shadowbox,
}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\newcommand{\mean}{3}
\newcommand{\std}{0.2}
\pgfmathdeclarefunction{gaussian}{2}{%
\pgfmathparse{1/(#1*sqrt(2*pi))*exp(-((x-#2)^2)/(2*#1^2))}%
}
\usetikzlibrary{intersections}
\usetikzlibrary{fillbetween}
\usetikzlibrary{patterns}
\usetikzlibrary{patterns.meta}
\usepgfplotslibrary{fillbetween}
\begin{document}
\begin{frame}
\titlepage
\begin{note}
{Introduce your self}
\end{note}
\end{frame}
% THIS IS THE FRAME OF CONCERN
\begin{frame}[fragile]
\begin{figure}
\begin{tikzpicture}[dot/.style = {circle, fill, inner sep=1.0pt, node contents={}}]
\begin{axis}[
no markers, domain=0:14, samples=200,
axis lines=none, %axis lines*=left,
xlabel=$x$, ylabel=$y$,
every axis y label/.style={at=(current axis.above origin),anchor=south},
every axis x label/.style={at=(current axis.right of origin),anchor=west},
height=5cm, width=17cm,
xtick={\mean,12.5}, ytick=\empty,
enlargelimits=false, clip=false, axis on top,
grid = major
]
% On crée les 2 courbes gaussiennes en les nommant et en les remplissant
\addplot [fill=cyan!20, draw=none, domain=0:14] {gaussian(1.5+\std,\mean)} \closedcycle;
\addplot [name path=haute,very thick,cyan!50!black] {gaussian(1.5+\std, \mean)+0.05};
\addplot [name path=basse,very thick,cyan!50!black] {gaussian(1.5+\std, \mean)};
\addplot [very thick,cyan!50!black] {gaussian(1.5+\std, \mean)+0.05}--(14,0); % ligne entre fin de la fonction et axe des abscisses
% On remplit la zone entre les 2 courbes
\addplot fill between[
of = haute and basse,
soft clip={domain=0:14},
every even segment/.style = {pink,opacity=.2}
];
% On crée une ligne artificielle pour fermer le contour à gauche
\draw[very thick, cyan!50!black] (0,0) -- (0,0.05011524462);
% On crée les indications pour les quantités H(x,t) et R(x,t)
\draw[dashed,red, stealth-stealth, very thick] (8,0) -- node[fill=cyan!20,scale=0.75] {$h(x,t)$} (8,0.189940);
\draw[dashed,red, stealth-stealth, thick] (7,0.025) -- node[fill=cyan!20,scale=0.75] {$R(x,t)$} (12.5,0.025);
% On remplit la zone intermédiaire entre les 2 rectangles gris (SANS CONTOURS)
\path[fill=cyan!20] (6.25,-0.2) -- (6.25,0) -- (7.75,0) -- (7.75,-0.2) -- (6.25,-0.2);
% On crée artificiellement 2 contours qui nous intéressent
\draw[black] (6.25,-0.2) -- (6.25,0);
\draw[black] (7.75,-0.2) -- (7.75,0);
% On construit les rectangles de la base à la main
\draw[black, fill=gray!20] (0,-0.075) -- (0,0) -- (6.25,0) -- (6.25,-0.075) -- (0,-0.075);
\draw[black, fill=gray!20] (14,-0.075) -- (14,0) -- (7.75,0) -- (7.75,-0.075) -- (14,-0.075);
\draw[black, pattern = checkerboard] (0,-0.12) -- (0,-0.075) -- (6.25,-0.075) -- (6.25,-0.12) -- (0,-0.12);
\draw[black, pattern = checkerboard] (14,-0.12) -- (14,-0.075) -- (7.75,-0.075) -- (7.75,-0.12) -- (14,-0.12);
% On crée le label sur le flux Q(x,t)
\draw [yshift=-0.6cm, -stealth](7,-0.1) -- node [fill=cyan!20] {$Q(t)$} (7,0);
\node[right] at (5.5,0.1) {$(\rho,\mu)$};
% On crée les flèches pour les zones à labeliser à la main
\draw[black, stealth-, very thick] (9,0.13) -- node[pos = 0.8,below right,scale=1] {Elastic membrane} (12,0.25);
\draw[black, stealth-, very thick] (6,0.03) -- node[pos = 0.8,below left,scale=1] {Silicon oil} (3,0.25);
\draw[black, -stealth, very thick] (5,-0.2) -- node[pos = 0.2,above left,scale=1] {Checkerboard pattern} (5,-0.12);
%\draw [yshift=-0.6cm, latex-latex](axis cs:4,0) -- node [fill=white] {$Q(t)$} (axis cs:5.96,0);
% Construction des axes
\draw[dotted,-stealth,thick] (7, 0) -- (15, 0) node[right] {$\underline{e}_x$}; % x-axis
\draw[dotted,-stealth,thick] (7, 0) -- ( 7,0.325) node[above] {$\underline{e}_z$}; % y-axis
\path (7,0) node[black,dot,label=below left:$0$];
\end{axis}
\end{tikzpicture}
\end{figure}
\end{frame}
\end{document}
其他的建议:
您无需加载 hyperref,beamer 会为您完成此操作。即使您必须加载它,也应将其作为最后一个包加载,而不是作为第一个包加载。
不要使用
\UseRawInputEncoding
不需要
amsmath
,xcolor
或者graphicx
,beamer 会为你加载所有这些不要使用
multicol
,beamer 有自己的柱状机构beamer 没有浮动机制,给出浮动说明符(例如
[h]
对于图形环境)没有多大意义beamer 的图形环境默认居中,不需要
\centering