pgfplots 中最后一个图被压低

pgfplots 中最后一个图被压低

由于某种原因,最右边的图表比其他图表略低,但我不知道为什么。

代码:

\documentclass[12pt]{article}
\usepackage{amsmath, amssymb}
\usepackage[usenames,dvipsnames,svgnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{positioning,calc}
\usepackage{pgfplots}

\begin{document}

\begin{center}
\setlength{\tabcolsep}{1em}
\begin{tabular}[ht]{m{8em} m{8em} m{8em} m{8em}}

\begin{tikzpicture} %y=x

\begin{axis}[grid=both,
axis lines=middle,
ticklabel style={fill=white,font=\scriptsize},
x=0.8cm,y=0.8cm,clip=false,
xmin=-2,xmax=2,xtick={-1,1},
ymin=-2,ymax=2,ytick={-1,1},
xlabel=\(x\),ylabel=\(y\),
samples=2]

\addplot[domain=-2:2,<->,>=latex] {x};

\end{axis}

\end{tikzpicture}

&
\begin{tikzpicture} %y=x^2

\begin{axis}[grid=both,
axis lines=middle,
ticklabel style={fill=white,font=\scriptsize},
x=0.8cm,y=0.8cm,clip=false,
xmin=-2,xmax=2,xtick={-1,1},
ymin=-1,ymax=3,ytick={1,2},
xlabel=\(x\),ylabel=\(y\),
samples=200]

\addplot[domain=-1.732:1.732,<->,>=latex] {x^2};

\end{axis}
\end{tikzpicture}

&
\begin{tikzpicture} %y=x^3

\begin{axis}[grid=both,
axis lines=middle,
ticklabel style={fill=white,font=\scriptsize},
x=0.8cm,y=0.8cm,clip=false,
xmin=-2,xmax=2,xtick={-1,1},
ymin=-2,ymax=2,ytick={-1,1},
xlabel=\(x\),ylabel=\(y\),
samples=200]

\addplot[domain=-1.260:1.260,<->,>=latex] {x^3};

\end{axis}
\end{tikzpicture}

&
\begin{tikzpicture} %y=x^4

\begin{axis}[grid=both,
axis lines=middle,
ticklabel style={fill=white,font=\scriptsize},
x=0.8cm,y=0.8cm,clip=false,
xmin=-2,xmax=2,xtick={-1,1},
ymin=-1,ymax=3,ytick={1,2},
xlabel=\(x\),ylabel=\(y\),
samples=200]

\addplot[domain=-1.316:1.316,<->,>=latex] {x^4};

\end{axis}
\end{tikzpicture}
\end{tabular}
\end{center}

\end{document}

由此得到下面的图像。

答案1

问题出在其他列中的图像。它们在 后面有一个空行\end{tikzpicture}。这个空行结束了段落。然后表格插入一个支柱(用于深度),从而开始一个新段落。

带 s 的版本\hline来说明表格行:

\documentclass[12pt]{article}
\usepackage{array}
\usepackage{amsmath, amssymb}
\usepackage[usenames,dvipsnames,svgnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{positioning,calc}
\usepackage{pgfplots}

\begin{document}

\begin{center}
\setlength{\tabcolsep}{1em}
\begin{tabular}[t]{m{8em} m{8em} m{8em} m{8em}}
\hline
\begin{tikzpicture} %y=x

\begin{axis}[grid=both,
axis lines=middle,
ticklabel style={fill=white,font=\scriptsize},
x=0.8cm,y=0.8cm,clip=false,
xmin=-2,xmax=2,xtick={-1,1},
ymin=-2,ymax=2,ytick={-1,1},
xlabel=\(x\),ylabel=\(y\),
samples=2]

\addplot[domain=-2:2,<->,>=latex] {x};

\end{axis}

\end{tikzpicture}
&
\begin{tikzpicture} %y=x^2

\begin{axis}[grid=both,
axis lines=middle,
ticklabel style={fill=white,font=\scriptsize},
x=0.8cm,y=0.8cm,clip=false,
xmin=-2,xmax=2,xtick={-1,1},
ymin=-1,ymax=3,ytick={1,2},
xlabel=\(x\),ylabel=\(y\),
samples=200]

\addplot[domain=-1.732:1.732,<->,>=latex] {x^2};

\end{axis}
\end{tikzpicture}
&
\begin{tikzpicture} %y=x^3

\begin{axis}[grid=both,
axis lines=middle,
ticklabel style={fill=white,font=\scriptsize},
x=0.8cm,y=0.8cm,clip=false,
xmin=-2,xmax=2,xtick={-1,1},
ymin=-2,ymax=2,ytick={-1,1},
xlabel=\(x\),ylabel=\(y\),
samples=200]

\addplot[domain=-1.260:1.260,<->,>=latex] {x^3};

\end{axis}
\end{tikzpicture}
&
\begin{tikzpicture} %y=x^4

\begin{axis}[grid=both,
axis lines=middle,
ticklabel style={fill=white,font=\scriptsize},
x=0.8cm,y=0.8cm,clip=false,
xmin=-2,xmax=2,xtick={-1,1},
ymin=-1,ymax=3,ytick={1,2},
xlabel=\(x\),ylabel=\(y\),
samples=200]

\addplot[domain=-1.316:1.316,<->,>=latex] {x^4};

\end{axis}
\end{tikzpicture}
\\\hline
\end{tabular}
\end{center}
\end{document}

结果

可以通过将图像降低大于支柱深度的量来避免图像下方的白色空间,例如通过baseline所有图像的选项:

\begin{tikzpicture}[baseline=2em]

固定结果

相关内容