垂直 y 轴对齐问题

垂直 y 轴对齐问题

我试图让下图中的垂直轴对齐,但遇到了麻烦。特别是,第三行中第一个和最后一个图的 y 轴必须与前几行的 y 轴对齐。其他问题包括:

  1. 星号和等号不在中心,
  2. 最后一栏的数字不按比例绘制,并且
  3. 字体太大。

谢谢。

在此处输入图片描述

\documentclass[aspectratio=169,11pt]{beamer}
\mode<presentation>

\usepackage{pgfpages,mathtools}

\usepackage{pgfplots}
\usepackage{tikz}

\usetikzlibrary{arrows,plotmarks}
\usetikzlibrary{matrix}

\usetheme{Boadilla}
\date{}

\begin{document}

\begin{frame}
  \frametitle{Examples}
  \begin{tikzpicture}[ampersand replacement=\&,baseline=(current bounding box.center)]
  \matrix{
    \begin{axis}[axis lines=middle, xtick={0,4},
     xticklabels={0,$T$},ymin=0, ymax=1.2,
     xmin=0,xmax=10,ytick={1},yticklabels={$1$},
     height=3cm,
     xlabel={\empty}, x label style={anchor=north},
     ylabel={\empty}, y label style={anchor=west}]
     \addplot+[very thick,mark=none,const plot]
     coordinates
     {(0,0) (0,1) (4,0)};
   \end{axis}

   \& \node (conv1) {$\ast$};

   \&\begin{axis}[%
     axis lines=middle, xtick={0,4},
     xticklabels={0,$T$},ymin=0, ymax=1.2,
     xmin=0,xmax=10,ytick={1},yticklabels={$1$},
     height=3cm,
     xlabel={\empty}, x label style={anchor=north},
     ylabel={\empty}, y label style={anchor=west}]
     \addplot+[very thick,mark=none,const plot]
     coordinates
     {(0,0) (0,1) (4,0)};
   \end{axis}

   \& \node (equal1) {$=$};

   \&\begin{axis}[%
     axis lines=middle, xtick={0,4,8},
     xticklabels={0,$T$,$2T$},ymin=0, ymax=1.2,
     xmin=0,xmax=10,ytick={1},yticklabels={$T$},
     height=3cm,
     xlabel={\empty}, x label style={anchor=north},
     ylabel={\empty}, y label style={anchor=west}]
     \addplot+[very thick,mark=none]
     coordinates
     {(0,0) (4,1) (8,0)};
   \end{axis}\\

   \begin{axis}[axis lines=middle, xtick={0,8},
     xticklabels={0,$2T$},ymin=0, ymax=1.2,
     xmin=0,xmax=10,ytick={1},yticklabels={$1$},
     height=3cm,
     xlabel={\empty}, x label style={anchor=north},
     ylabel={\empty}, y label style={anchor=west}]
     \addplot+[very thick,mark=none,const plot]
     coordinates
     {(0,0) (0,1) (8,0)};
   \end{axis}

   \& \node (conv2) {$\ast$};

   \&\begin{axis}[axis lines=middle, xtick={0,4},
     xticklabels={0,$T$},ymin=0, ymax=1.2,
     xmin=0,xmax=10,ytick={1},yticklabels={$1$},
     height=3cm,
     xlabel={\empty}, x label style={anchor=north},
     ylabel={\empty}, y label style={anchor=west}]
     \addplot+[very thick,mark=none,const plot]
     coordinates
     {(0,0) (0,1) (4,0)};
   \end{axis}

   \& \node (equal2) {$=$};

   \&\begin{axis}[axis lines=middle, xtick={0,4,8,12},
     xticklabels={0,$T$,$2T$,$3T$},ymin=0, ymax=1.2,
     xmin=0,xmax=13,ytick={1},yticklabels={$T$},
     height=3cm,
     xlabel={\empty}, x label style={anchor=north},
     ylabel={\empty}, y label style={anchor=west}]
     \addplot+[very thick,mark=none]
     coordinates
     {(0,0) (4,1) (8,1) (12,0)};
   \end{axis}\\

   \begin{axis}[axis lines=middle, xtick={-4,0},
     xticklabels={$-T$,0},ymin=0, ymax=1.2,
     xmin=-5,xmax=5,ytick={1},yticklabels={$1$},
     height=3cm,
     y tick label style={anchor=west},
     xlabel={\empty}, x label style={anchor=north},
     ylabel={\empty}, y label style={anchor=west}]
     \addplot+[very thick,mark=none,const plot]
     coordinates
     {(-4,0) (-4,1) (0,0)};
   \end{axis}

   \& \node (conv3) {$\ast$};

   \&\begin{axis}[axis lines=middle, xtick={0,4},
     xticklabels={0,$T$},ymin=0, ymax=1.2,
     xmin=0,xmax=10,ytick={1},yticklabels={$1$},
     height=3cm,
     xlabel={\empty}, x label style={anchor=north},
     ylabel={\empty}, y label style={anchor=west}]
     \addplot+[very thick,mark=none,const plot]
     coordinates
     {(0,0) (0,1) (4,0)};
   \end{axis}

   \& \node (equal3) {$=$};

   \&\begin{axis}[axis lines=middle, xtick={-4,0,4},
     xticklabels={$-T$,$0$,$T$},ymin=0, ymax=1.2,
     xmin=-5,xmax=5,ytick={1},yticklabels={$T$},
     height=3cm,
     xlabel={\empty}, x label style={anchor=north},
     ylabel={\empty}, y label style={anchor=west}]
     \addplot+[very thick,mark=none]
     coordinates
     {(-4,0) (0,1) (4,0)};
   \end{axis}\\
 };
\end{tikzpicture}%
\end{frame}

\end{document}

答案1

如果你添加

every axis/.append style={
footnotesize,
height=3cm,
unit vector ratio=1 4 1,
execute at end axis={
   \coordinate (O) at (current axis.east -| current axis.origin);
   },
anchor=O,

对于tikzpicture选项,你会得到

在此处输入图片描述

看起来好些了吗?(样式中添加的通用设置every axis已从各个轴中删除。)

还要注意,这xlabel=\empty有点奇怪。该\empty宏用于刻度(xtick/ ytick/ ztick),适用于您根本不想要任何刻度的情况。如果您不需要xlabel,只需将xlabel=..其全部删除。(然后您也可以删除x label style。)

\documentclass[aspectratio=169,11pt]{beamer}
\mode<presentation>

\usepackage{pgfpages,mathtools}

\usepackage{pgfplots}

\usetikzlibrary{arrows,plotmarks}
\usetikzlibrary{matrix}

\usetheme{Boadilla}
\date{}

\begin{document}

\begin{frame}
  \frametitle{Examples}
  \begin{tikzpicture}[
   ampersand replacement=\&,
   baseline=(current bounding box.center),
   every axis/.append style={
    footnotesize,
    height=3cm,
    unit vector ratio=1 4 1,
    execute at end axis={
       \coordinate (O) at (current axis.east -| current axis.origin);
       },
    anchor=O
    }
   ]
  \matrix{
    \begin{axis}[axis lines=middle, xtick={0,4},
     xticklabels={0,$T$},ymin=0, ymax=1.2,
     xmin=0,xmax=10,ytick={1},yticklabels={$1$},
     ]
     \addplot+[very thick,mark=none,const plot]
     coordinates
     {(0,0) (0,1) (4,0)};
   \end{axis}

   \& \node (conv1) {$\ast$};

   \&\begin{axis}[%
     axis lines=middle, xtick={0,4},
     xticklabels={0,$T$},ymin=0, ymax=1.2,
     xmin=0,xmax=10,ytick={1},yticklabels={$1$},
     ]
     \addplot+[very thick,mark=none,const plot]
     coordinates
     {(0,0) (0,1) (4,0)};
   \end{axis}

   \& \node (equal1) {$=$};

   \&\begin{axis}[%
     axis lines=middle, xtick={0,4,8},
     xticklabels={0,$T$,$2T$},ymin=0, ymax=1.2,
     xmin=0,xmax=10,ytick={1},yticklabels={$T$},
     ]
     \addplot+[very thick,mark=none]
     coordinates
     {(0,0) (4,1) (8,0)};
   \end{axis}\\

   \begin{axis}[axis lines=middle, xtick={0,8},
     xticklabels={0,$2T$},ymin=0, ymax=1.2,
     xmin=0,xmax=10,ytick={1},yticklabels={$1$},
     ]
     \addplot+[very thick,mark=none,const plot]
     coordinates
     {(0,0) (0,1) (8,0)};
   \end{axis}

   \& \node (conv2) {$\ast$};

   \&\begin{axis}[axis lines=middle, xtick={0,4},
     xticklabels={0,$T$},ymin=0, ymax=1.2,
     xmin=0,xmax=10,ytick={1},yticklabels={$1$},
     ]
     \addplot+[very thick,mark=none,const plot]
     coordinates
     {(0,0) (0,1) (4,0)};
   \end{axis}

   \& \node (equal2) {$=$};

   \&\begin{axis}[axis lines=middle, xtick={0,4,8,12},
     xticklabels={0,$T$,$2T$,$3T$},ymin=0, ymax=1.2,
     xmin=0,xmax=13,ytick={1},yticklabels={$T$},
     ]
     \addplot+[very thick,mark=none]
     coordinates
     {(0,0) (4,1) (8,1) (12,0)};
   \end{axis}\\

   \begin{axis}[axis lines=middle, xtick={-4,0},
     xticklabels={$-T$,0},ymin=0, ymax=1.2,
     xmin=-5,xmax=5,ytick={1},yticklabels={$1$},
     y tick label style={anchor=west},
     ]
     \addplot+[very thick,mark=none,const plot]
     coordinates
     {(-4,0) (-4,1) (0,0)};
   \end{axis}

   \& \node (conv3) {$\ast$};

   \&\begin{axis}[axis lines=middle, xtick={0,4},
     xticklabels={0,$T$},ymin=0, ymax=1.2,
     xmin=0,xmax=10,ytick={1},yticklabels={$1$},
     ]
     \addplot+[very thick,mark=none,const plot]
     coordinates
     {(0,0) (0,1) (4,0)};
   \end{axis}

   \& \node (equal3) {$=$};

   \&\begin{axis}[axis lines=middle, xtick={-4,0,4},
     xticklabels={$-T$,$0$,$T$},ymin=0, ymax=1.2,
     xmin=-5,xmax=5,ytick={1},yticklabels={$T$},
     ]
     \addplot+[very thick,mark=none]
     coordinates
     {(-4,0) (0,1) (4,0)};
   \end{axis}\\
 };
\end{tikzpicture}%
\end{frame}
\end{document}

答案2

这是解决地块之间的中心\ast和符号问题的方法=

  • 首先,您需要用name=A、B、...、I 来命名图。
  • 然后你可以放置包含\ast=符号的节点,像这样

 \foreach \i/\j in {A/B,D/E,G/H}
{\path (\i.south east)--node{$\ast$}(\j.south west);}
\foreach \i/\j in {B/C,E/F,H/I}
{\path (\i.south east)--node{$=$}(\j.south west);} 

完整代码

\documentclass[aspectratio=169,11pt]{beamer}
\mode<presentation>

\usepackage{pgfpages,mathtools}

\usepackage{pgfplots}

\usetikzlibrary{arrows,plotmarks}
\usetikzlibrary{matrix}

\usetheme{Boadilla}
\date{}

\begin{document}

\begin{frame}
  \frametitle{Examples}
  \begin{tikzpicture}[ampersand replacement=\&,baseline=(current bounding box.center),
  every axis/.append style={ymin=0, ymax=1.2,height=3cm,
     font=\scriptsize,xlabel={\empty}, 
     x label style={anchor=north},
     ylabel={\empty}, y label style={anchor=west},
     axis lines=middle,,xmin=0,xmax=10}]

  \matrix[column sep=3mm]{
    \begin{axis}[name=A,axis lines=middle, xtick={0,4},
     xticklabels={0,$T$},yticklabels={$1$},ytick={1}]
          \addplot+[very thick,mark=none,const plot]
     coordinates
     {(0,0) (0,1) (4,0)};
   \end{axis}

   \& 

   \&\begin{axis}[%
     name=B, xtick={0,4},
     xticklabels={0,$T$},ytick={1},yticklabels={$1$}]
     \addplot+[very thick,mark=none,const plot]
     coordinates
     {(0,0) (0,1) (4,0)};
   \end{axis}

   \& 

   \&\begin{axis}[%
     name=C, xtick={0,4,8},
     xticklabels={0,$T$,$2T$},ytick={1},yticklabels={$T$}]
     \addplot+[very thick,mark=none]
     coordinates
     {(0,0) (4,1) (8,0)};
   \end{axis}\\

   \begin{axis}[name=D, xtick={0,8},
     xticklabels={0,$2T$},ytick={1},yticklabels={$1$}]
     \addplot+[very thick,mark=none,const plot]
     coordinates
     {(0,0) (0,1) (8,0)};
   \end{axis}

   \& 

   \&\begin{axis}[name=E, xtick={0,4},
     xticklabels={0,$T$},
     ytick={1},yticklabels={$1$}]
     \addplot+[very thick,mark=none,const plot]
     coordinates
     {(0,0) (0,1) (4,0)};
   \end{axis}

   \& 

   \&\begin{axis}[name=F, xtick={0,4,8,12},
     xticklabels={0,$T$,$2T$,$3T$},
     xmax=13,ytick={1},yticklabels={$T$}]
     \addplot+[very thick,mark=none]
     coordinates
     {(0,0) (4,1) (8,1) (12,0)};
   \end{axis}\\

   \begin{axis}[name=G, xtick={-4,0},
     xticklabels={$-T$,0},
     xmin=-5,xmax=5,ytick={1},yticklabels={$1$}]
     \addplot+[very thick,mark=none,const plot]
     coordinates
     {(-4,0) (-4,1) (0,0)};
   \end{axis}

   \& 

   \&\begin{axis}[name=H, xtick={0,4},
     xticklabels={0,$T$},ytick={1},yticklabels={$1$}]
     \addplot+[very thick,mark=none,const plot]
     coordinates
     {(0,0) (0,1) (4,0)};
   \end{axis}

   \& 

   \&\begin{axis}[name=I, xtick={-4,0,4},
     xticklabels={$-T$,$0$,$T$},
     xmin=-5,xmax=5,ytick={1},yticklabels={$T$}]
     \addplot+[very thick,mark=none]
     coordinates
     {(-4,0) (0,1) (4,0)};
   \end{axis}\\
 };

 \foreach \i/\j in {A/B,D/E,G/H}
{\path (\i.south east)--node{$\ast$}(\j.south west);}
\foreach \i/\j in {B/C,E/F,H/I}
{\path (\i.south east)--node{$=$}(\j.south west);} 
\end{tikzpicture}%
\end{frame}

\结束{文档} 在此处输入图片描述

相关内容