![使用 tikz 在 beamer 中绘制六张图表](https://linux22.com/image/420137/%E4%BD%BF%E7%94%A8%20tikz%20%E5%9C%A8%20beamer%20%E4%B8%AD%E7%BB%98%E5%88%B6%E5%85%AD%E5%BC%A0%E5%9B%BE%E8%A1%A8.png)
我正在尝试设置一个带有 6 个图形的投影仪,这些图形排列成 2x3 矩阵。但是,当我尝试调整图形大小以使其适合框架时,图片不会移动或开始出现奇怪的现象。我尝试过使用其他环境(如minipage
或 )columns
,也尝试过命令(如\scalebox
或 ),\resizebox
但收效甚微。
下面我留下了一个 MWE 和我的代码结果。任何帮助将 6 个图表放入投影仪的帮助都将不胜感激
\documentclass[usenames,dvipsnames]{beamer}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing}
\usetikzlibrary{fit, calc, matrix, positioning, arrows.meta, intersections, through, backgrounds, patterns}
\usepackage{pgfplots}
\pgfplotsset{compat = newest}
\usepgfplotslibrary{fillbetween}
\pgfplotsset{overwrite option/.style args={#1 with #2}{#1=#2,#1/.code=}}
\pgfplotsset{
vasymptote/.style={before end axis/.append code={\draw[dashed,<->,-{Latex}] ({rel axis cs:0,0} -| {axis cs:#1,0}) -- ({rel axis cs:0,1} -| {axis cs:#1,0}); }},
myaxis/.style={axis line style={<->, {Latex}-{Latex}}}
} % This fancy shit sets the arrows to both parts of the axis in the axis environment of pgfplot
\begin{frame}{FUNCTIONS}
\framesubtitle{GRAPHS}
\begin{figure}[htb]
\centering % <-- added
\begin{subfigure}{0.25\textwidth}
\include{Figures/function1}
\caption{image1}
\end{subfigure}\hfil % <-- added
\begin{subfigure}{0.25\textwidth}
\include{Figures/function1}
\caption{image2}
\end{subfigure}\hfil % <-- added
\begin{subfigure}{0.25\textwidth}
\include{Figures/function1}
\caption{image3}
\end{subfigure}
\medskip
\begin{subfigure}{0.25\textwidth}
\include{Figures/function1}
\caption{image4}
\end{subfigure}\hfil % <-- added
\begin{subfigure}{0.25\textwidth}
\include{Figures/function1}
\caption{image5}
\end{subfigure}\hfil % <-- added
\begin{subfigure}{0.25\textwidth}
\include{Figures/function1}
\caption{image6}
\end{subfigure}
\caption{Fasi del processo di impregnazione}
\end{figure}
\end{frame}
% imported graph
% Exponencial function
\begin{tikzpicture}
\begin{axis}[
width=6cm,
xscale = 1, yscale = 1,
axis lines = middle,
myaxis,
grid,
grid style={densely dashed},
xmin = -5.5, xmax = 5.5, ymin = -5.5, ymax = 5.5,
every axis/.append style={font=\tiny},
xlabel = {$x$}, xlabel style={at=(current axis.right of origin), anchor=west},
ylabel = $y$, ylabel style={at=(current axis.above origin), anchor=east},
xtick = {-4,-2,0,2,4},
% xticklables = {-2,0,2,4,6},
ytick = {-4,-2,0,2,4},
% yticklables = {-2,0,2,4,6},
samples=100,
domain=-5.5:5.5,
axis equal,
% no markers
]
\addplot[domain=-5:5, thick, RoyalBlue, name path = rb]{exp(x)} node[above, rotate = 0] at (2,2) {\large $e^x$} ;
path = xaxis] (axis cs:0,0) -- (axis cs:1,0);
\end{axis}
\end{tikzpicture}
答案1
\begin{filecontents*}{function1.tex}
\begin{tikzpicture}
\begin{axis}[
axis lines = middle,
myaxis,
grid,
grid style={densely dashed},
xmin = -5.5, xmax = 5.5, ymin = -5.5, ymax = 5.5,
every axis/.append style={font=\tiny},
xlabel = {$x$}, xlabel style={at=(current axis.right of origin), anchor=west},
ylabel = $y$, ylabel style={at=(current axis.above origin), anchor=east},
xtick = {-4,-2,0,2,4},
% xticklables = {-2,0,2,4,6},
ytick = {-4,-2,0,2,4},
% yticklables = {-2,0,2,4,6},
samples=100,
domain=-5.5:5.5,
axis equal,
% no markers
]
\addplot[domain=-5:5, thick, RoyalBlue, name path = rb]{exp(x)} node[above, rotate = 0] at
(2,2) {\large $e^x$} ;
path = xaxis] (axis cs:0,0) -- (axis cs:1,0);
\end{axis}
\end{tikzpicture}
\end{filecontents*}
\documentclass[usenames,dvipsnames]{beamer}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing}
\usetikzlibrary{fit, calc, matrix, positioning, arrows.meta, intersections, through,
backgrounds, patterns}
\usepackage{pgfplots}
\pgfplotsset{compat = newest}
\usepgfplotslibrary{fillbetween}
\pgfplotsset{overwrite option/.style args={#1 with #2}{#1=#2,#1/.code=}}
\pgfplotsset{
vasymptote/.style={before end axis/.append code={\draw[dashed,<->,-{Latex}] ({rel axis
cs:0,0} -| {axis cs:#1,0}) -- ({rel axis cs:0,1} -| {axis cs:#1,0}); }},
myaxis/.style={axis line style={<->, {Latex}-{Latex}}}
} % This fancy shit sets the arrows to both parts of the axis in the axis environment of
%pgfplot
\usepackage{subcaption}
\def\myScale{0.75}
\begin{document}
\begin{frame}{FUNCTIONS}{GRAPHS}
\begin{figure}
\begin{subfigure}{0.33\textwidth}
\scalebox{\myScale}{\input{function1}}
\caption{image1}
\end{subfigure}\hfill
\begin{subfigure}{0.33\textwidth}
\scalebox{\myScale}{\input{function1}}
\caption{image2}
\end{subfigure}\hfill
\begin{subfigure}{0.33\textwidth}
\scalebox{\myScale}{\input{function1}}
\caption{image3}
\end{subfigure}
\begin{subfigure}{0.33\textwidth}
\scalebox{\myScale}{\input{function1}}
\caption{image4}
\end{subfigure}\hfill
\begin{subfigure}{0.33\textwidth}
\scalebox{\myScale}{\input{function1}}
\caption{image5}
\end{subfigure}\hfill
\begin{subfigure}{0.33\textwidth}
\scalebox{\myScale}{\input{function1}}
\caption{image6}
\end{subfigure}
\caption{Fasi del processo di impregnazione}
\end{figure}
\end{frame}
\end{document}