附录

附录

我有 5 个不同的 xy 坐标平面,我想将它们对齐。具体来说,我想将 3 个放在一行,将 2 个放在下一行,并将 x 轴全部对齐在同一行内。我制作了图表并将它们放在两个单独的行中,但我无法让它们很好地对齐。

这是一个最小工作示例:

\documentclass[border=10pt]{standalone}
 \usepackage{tikz,amsmath}
 \usepackage{tabularx}


 \begin{document}

   \begin{tabular}{ccc}
    \begin{tikzpicture}[scale=0.175] 
    \draw[<->] (-4,0)--(4,0); \draw[<->] (0,-6)--(0,6); \node at (4.5,0) {$x$};
    \node at (0,6.5) {$y$};  \draw[green, ultra thick, domain=-1.5:3] plot (\x, {4+3* \x-2*\x*\x}); 
   \draw[very thick,black](-0.3,3.95) node[left=1pt]{(A)}; \end{tikzpicture}  &
   \noindent  \begin{tikzpicture}[scale=0.175] \draw[<->] (-4,0)--(4,0); \draw[<->] (0,-6)--(0,6); 
   \node at (4.5,0) {$x$};
   \node at (0,6.5) {$y$}; 
   \draw[green, ultra thick, domain=-1.3:2.6] plot (\x, {-2+3*\x-2*\x*\x});
  \draw[very thick,black](-0.3,3.95) node[left=1pt]{(B)}; \end{tikzpicture} &
  \noindent \begin{tikzpicture}[scale=0.175] \draw[<->] (-4,0)--(4,0);         
   \draw[<->] (0,-6)--(0,6); \node at (4.5,0) {$x$};
   \node at (0,6.5) {$y$};  \draw[green, ultra thick, domain=-2.5:1.05] plot (\x, {-2+3*\x+2*\x*\x}); 
  \draw[very thick,black](-0.3,3.95) node[left=1pt]{(C)}; \end{tikzpicture} \\[1em]
  \noindent \begin{tikzpicture}[scale=0.175] \draw[<->] (-4,0)--(4,0); \draw[<->] (0,-6)--(0,6); \node at (4.5,0) {$x$};
  \node at (0,6.5) {$y$};  \draw[green, ultra thick, domain=-1.6:2.9] plot (\x, {0+3*\x-2*\x*\x}); 
  \draw[very thick,black](-0.3,3.95) node[left=1pt]{(D)}; \end{tikzpicture} &
  \noindent \begin{tikzpicture}[scale=0.175] \draw[<->] (-4,0)--(4,0);           
  \draw[<->] (0,-6)--(0,6); \node at (4.5,0) {$x$};
   \node at (0,6.5) {$y$};  \draw[green, ultra thick, domain=-2.3:0.8] plot (\x, {-2-3*\x-2*\x*\x}); 
   \draw[very thick,black](-0.3,3.95) node[left=1pt]{(E)};          
   \end{tikzpicture} &
    \\
  \end{tabular}

  \end{document}

答案1

简短版本:baseline={(0,0)}作为选项添加到每个tikzpicture

较长的版本:

每个tikzpicture只是一个盒子,每个盒子的底部都是对齐的,基线是盒子的底部。baseline={(0,0)}将基线更改为原点所在的级别,即(0,0),在tikzpicture,使其成为参考,而不是盒子的底部。

因此,改变每一个

 \begin{tikzpicture}[scale=0.175]      

 \begin{tikzpicture}[scale=0.175,baseline={(0,0)}]

完整代码如下。s\noindent不执行任何操作,因此我将其删除。

在此处输入图片描述

\documentclass[border=10pt]{standalone}
 \usepackage{tikz,amsmath}

 \begin{document}

   \begin{tabular}{ccc}
    \begin{tikzpicture}[scale=0.175,baseline={(0,0)}] 
    \draw[<->] (-4,0)--(4,0); \draw[<->] (0,-6)--(0,6); \node at (4.5,0) {$x$};
    \node at (0,6.5) {$y$};  \draw[green, ultra thick, domain=-1.5:3] plot (\x, {4+3* \x-2*\x*\x}); 
   \draw[very thick,black](-0.3,3.95) node[left=1pt]{(A)}; \end{tikzpicture}  &
   \begin{tikzpicture}[scale=0.175,baseline={(0,0)}] \draw[<->] (-4,0)--(4,0); \draw[<->] (0,-6)--(0,6); 
   \node at (4.5,0) {$x$};
   \node at (0,6.5) {$y$}; 
   \draw[green, ultra thick, domain=-1.3:2.6] plot (\x, {-2+3*\x-2*\x*\x});
  \draw[very thick,black](-0.3,3.95) node[left=1pt]{(B)}; \end{tikzpicture} &
  \begin{tikzpicture}[scale=0.175,baseline={(0,0)}] \draw[<->] (-4,0)--(4,0);         
   \draw[<->] (0,-6)--(0,6); \node at (4.5,0) {$x$};
   \node at (0,6.5) {$y$};  \draw[green, ultra thick, domain=-2.5:1.05] plot (\x, {-2+3*\x+2*\x*\x}); 
  \draw[very thick,black](-0.3,3.95) node[left=1pt]{(C)}; \end{tikzpicture} \\[1em]
  \begin{tikzpicture}[scale=0.175,baseline={(0,0)}] \draw[<->] (-4,0)--(4,0); \draw[<->] (0,-6)--(0,6); \node at (4.5,0) {$x$};
  \node at (0,6.5) {$y$};  \draw[green, ultra thick, domain=-1.6:2.9] plot (\x, {0+3*\x-2*\x*\x}); 
  \draw[very thick,black](-0.3,3.95) node[left=1pt]{(D)}; \end{tikzpicture} &
  \begin{tikzpicture}[scale=0.175,baseline={(0,0)}] \draw[<->] (-4,0)--(4,0);           
  \draw[<->] (0,-6)--(0,6); \node at (4.5,0) {$x$};
   \node at (0,6.5) {$y$};  \draw[green, ultra thick, domain=-2.3:0.8] plot (\x, {-2-3*\x-2*\x*\x}); 
   \draw[very thick,black](-0.3,3.95) node[left=1pt]{(E)};          
   \end{tikzpicture} &
  \end{tabular}

  \end{document}

附录

您的代码中有很多重复,每个代码tikzpicture的布局基本相同,每个代码中绘制了不同的函数。您可以创建一个新命令,在给定域和函数的情况下为您创建此类图。下面是使用的示例pgfplots。(不确定我为什么使用pgfplots而不是您的代码...)

还添加了其他代码,以便进行比较。

在此处输入图片描述

\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}

\newcommand\myplot[3][]{% 1st arg: label in axis, 2nd arg: domain, 3rd arg: function
\begin{tikzpicture}[baseline={(0,0)}]
\begin{axis}[
 axis lines=middle,
 x axis line style={<->},
 y axis line style={<->}, 
 xtick=\empty, ytick=\empty,
 width=1.2cm,  % set width of axis
 height=2cm,   % set height of axis
 scale only axis,
 xmin=-4,xmax=4,
 ymin=-6,ymax=6,
 xlabel={$x$},
 ylabel={$y$},
 domain=#2,
 clip=false,
 anchor=center,
 xlabel style={at={(axis cs:4,0)},right},
 ylabel style={at={(axis cs:0,6)},above}, 
 ]
 \addplot [green,ultra thick,no marks] {#3};
 \node at (axis cs:-3,4) {#1};
\end{axis}
\end{tikzpicture}} 

\begin{document}
\begin{tabular}{ccc}
 \myplot[(A)]{-1.5:3}{4 + 3*x - 2*x^2} &
 \myplot[(B)]{-1.3:2.6}{-2 + 3*x - 2*x^2} &
 \myplot[(C)]{-2.5:1.05}{-2 + 3*x + 2*x^2} \\
 \myplot[(D)]{-1.6:2.9}{3*x - 2*x^2} &
 \myplot[(E)]{-2.3:0.8}{-2 - 3*x - 2*x^2}
\end{tabular}

\begin{tabular}{ccc}
    \begin{tikzpicture}[scale=0.175,baseline={(0,0)}] 
    \draw[<->] (-4,0)--(4,0); \draw[<->] (0,-6)--(0,6); \node at (4.5,0) {$x$};
    \node at (0,6.5) {$y$};  \draw[green, ultra thick, domain=-1.5:3] plot (\x, {4+3* \x-2*\x*\x}); 
   \draw[very thick,black](-0.3,3.95) node[left=1pt]{(A)}; \end{tikzpicture}  &
   \begin{tikzpicture}[scale=0.175,baseline={(0,0)}] \draw[<->] (-4,0)--(4,0); \draw[<->] (0,-6)--(0,6); 
   \node at (4.5,0) {$x$};
   \node at (0,6.5) {$y$}; 
   \draw[green, ultra thick, domain=-1.3:2.6] plot (\x, {-2+3*\x-2*\x*\x});
  \draw[very thick,black](-0.3,3.95) node[left=1pt]{(B)}; \end{tikzpicture} &
  \begin{tikzpicture}[scale=0.175,baseline={(0,0)}] \draw[<->] (-4,0)--(4,0);         
   \draw[<->] (0,-6)--(0,6); \node at (4.5,0) {$x$};
   \node at (0,6.5) {$y$};  \draw[green, ultra thick, domain=-2.5:1.05] plot (\x, {-2+3*\x+2*\x*\x}); 
  \draw[very thick,black](-0.3,3.95) node[left=1pt]{(C)}; \end{tikzpicture} \\[1em]
  \begin{tikzpicture}[scale=0.175,baseline={(0,0)}] \draw[<->] (-4,0)--(4,0); \draw[<->] (0,-6)--(0,6); \node at (4.5,0) {$x$};
  \node at (0,6.5) {$y$};  \draw[green, ultra thick, domain=-1.6:2.9] plot (\x, {0+3*\x-2*\x*\x}); 
  \draw[very thick,black](-0.3,3.95) node[left=1pt]{(D)}; \end{tikzpicture} &
  \begin{tikzpicture}[scale=0.175,baseline={(0,0)}] \draw[<->] (-4,0)--(4,0);           
  \draw[<->] (0,-6)--(0,6); \node at (4.5,0) {$x$};
   \node at (0,6.5) {$y$};  \draw[green, ultra thick, domain=-2.3:0.8] plot (\x, {-2-3*\x-2*\x*\x}); 
   \draw[very thick,black](-0.3,3.95) node[left=1pt]{(E)};          
   \end{tikzpicture} &
  \end{tabular}

\end{document}

相关内容