投影仪模式下 Tikz 图形的缩放问题

投影仪模式下 Tikz 图形的缩放问题

我正在尝试在 beamer 模板中使用 tikz 图形,但是我对要显示的图形的缩放比例有疑问。

这是用于绘制模板的代码:

    % !TEX encoding = UTF-8 Unicode
\documentclass[french]{beamer}
\usepackage{hyperref}
\usepackage[utf8]{inputenc}

%\usepackage[T1]{fontenc}
%\UseRawInputEncoding

\usepackage{pgfplots}
\usepackage{pgfpages}
\usepackage{pgf, tikz, adjustbox}

\usetikzlibrary{arrows.meta,
                patterns.meta
                }
\usepgfplotslibrary{fillbetween}
\usetikzlibrary{patterns, matrix, positioning}                


\pgfmathdeclarefunction{gaussian}{2}
{%
    \pgfmathparse{(1/(#1 * sqrt(2 * pi))) * exp((-1 / 2) * (((x - #2)/#1) ^ 2))}%
}
\pgfmathsetmacro{\mean}{7}
\pgfmathsetmacro{\std}{0.3}

% 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}




\begin{frame}

\begin{figure}  
\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 的初学者)?

在此先感谢您的帮助,

编辑:这是绘制图形的原始文档的代码:

\documentclass{article}


%%%%%%%%MATHS%%%%%%%%%%%%%
\usepackage{amsmath}
\usepackage{breqn}
\usepackage{amsfonts}
\usepackage{bm}
\usepackage{xcolor}
\usepackage{accents} % for bar under character

\DeclareMathOperator{\e}{e}

%%%%%% PGFPLOTS %%%%%%%%%%%%
\usepackage{pgfplots}
\pgfplotsset{compat=newest}

\pgfmathdeclarefunction{gaussian}{2}
{%
    \pgfmathparse{(1/(#1 * sqrt(2 * pi))) * exp((-1 / 2) * (((x - #2)/#1) ^ 2))}%
}
\pgfmathsetmacro{\mean}{7}
\pgfmathsetmacro{\std}{0.3}



%%%%%%%%COLORS%%%%%%%%%%%%%
\usepackage{color} %red, green, blue, yellow, cyan, magenta, black, white
\definecolor{mygreen}{RGB}{28,172,0} % color values Red, Green, Blue
\definecolor{mylilas}{RGB}{170,55,241}
\definecolor{BgYellow}{HTML}{FFF59C}
\definecolor{FrameYellow}{HTML}{F7A600}

%%%%%%%%GEOMETRIE%%%%%%%%%%%
\usepackage{geometry}
\usepackage{layout}
\geometry{hmargin=1cm,vmargin=1.5cm}
\newcommand{\gap}{\vspace{0.25cm}} 
\newcommand{\gapi}{\vspace{1.25cm}} 
 \usepackage{parskip}
 \usepackage{caption}

%%%%%%%%SECTIONS/AGENCEMENT%%%
\usepackage{enumitem}
\usepackage{pgf, tikz, adjustbox}
\usetikzlibrary{spy}
\usepgfplotslibrary{fillbetween}
\usetikzlibrary{patterns, matrix, positioning}
\usetikzlibrary{arrows.meta,
                patterns.meta
                }



\author{XXX}

\begin{document}

\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{document}

答案1

  • \pgfplotsset{compat=newest}在您尝试将代码移植到 beamer 时缺少该代码。

  • 您可以使用scale=...缩放完整的 tikz 图片:


\documentclass[french]{beamer}
\usepackage[utf8]{inputenc}

% other packages
\usepackage{booktabs,calligra}
\usepackage{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,
}

%%%%%% PGFPLOTS %%%%%%%%%%%%
\usepackage{pgfplots}
\pgfplotsset{compat=newest}

\pgfmathdeclarefunction{gaussian}{2}
{%
    \pgfmathparse{(1/(#1 * sqrt(2 * pi))) * exp((-1 / 2) * (((x - #2)/#1) ^ 2))}%
}
\pgfmathsetmacro{\mean}{7}
\pgfmathsetmacro{\std}{0.3}
\definecolor{mygreen}{RGB}{28,172,0} % color values Red, Green, Blue
\definecolor{mylilas}{RGB}{170,55,241}
\definecolor{BgYellow}{HTML}{FFF59C}
\definecolor{FrameYellow}{HTML}{F7A600}
\usepackage{pgf, tikz, adjustbox}
\usetikzlibrary{spy}
\usepgfplotslibrary{fillbetween}
\usetikzlibrary{patterns, matrix, positioning}
\usetikzlibrary{arrows.meta,
                patterns.meta
                }




\begin{document}
\begin{frame}
\begin{figure}
\begin{tikzpicture}[dot/.style = {circle, fill, inner sep=1.0pt, node contents={}},scale=0.6]

\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}

在此处输入图片描述

相关内容