如何更好地对齐这两个 tikz 图形?

如何更好地对齐这两个 tikz 图形?

我对 Latex 还不太熟悉,我想让两个 tikz 图形并排显示。老实说,我刚刚查过“tikz 图形并排显示”,然后获取代码并重新调整以提供我想要的图形,因此下面代码的某些部分可能看起来是不必要的。

\begin{figure}[h]
\centering
\begin{subfigure}[b]{0.3\textwidth}
\centering
\tdplotsetmaincoords{60}{30}
\begin{tikzpicture}[scale=1.55,tdplot_main_coords]
\filldraw[
    draw=gray,
    fill=gray!40,
]          (1,1,0)
        -- (0,1,0)
        -- (0,-1,0)
        -- (1,-1,0)
        -- cycle;
\draw[thin,->] (-1,0,0) -- (1,0,0) node[anchor=north east]{$x$};
\draw[ultra thick] (0,0,0) -- (0,1,0);
\draw[ultra thick] (0,0,0) -- (1,0,0);
\draw[ultra thick] (0,0,0) -- (0,-1,0);
\draw[thin,->] (0,-1,0) -- (0,1,0) node[anchor=north west]{$y$};
\draw[thin,->] (0,0,-1) -- (0,0,1) node[anchor=south]{$z$};
\end{tikzpicture}
\caption{The cone $\sigma$}
\end{subfigure}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~\begin{subfigure}[b]{0.3\textwidth}
\centering
\tdplotsetmaincoords{60}{30}
\begin{tikzpicture}[scale=1.55,tdplot_main_coords]
\filldraw[
    draw=gray,
    fill=gray!40,
]          (1,0,1)
        -- (1,0,-1)
        -- (0,0,-1)
        -- (0,0,1)
        -- cycle;
\draw[thin,->] (-1,0,0) -- (1,0,0) node[anchor=north east]{$x$};
\draw[ultra thick] (0,0,-1) -- (0,0,1);
\draw[ultra thick] (0,0,0) -- (1,0,0);
\draw[thin,->] (0,-1,0) -- (0,1,0) node[anchor=north west]{$y$};
\draw[thin,->] (0,0,-1) -- (0,0,1) node[anchor=south]{$z$};
\end{tikzpicture}
\caption{The dual cone $\sigma^*$}
\end{subfigure}
\caption{$Cone((1,0,0),(0,1,0),(0,-1,0))$ and its dual cone.}
\end{figure}

这会创建如下图形;

在此处输入图片描述

不过我有个小抱怨。左图的 z 轴底部与右图的 z 轴底部不对齐。如果它们对齐的话,对我来说会更整齐,但我不知道该怎么做。有什么帮助吗?

答案1

你可以使用以下想法:

  • 测量大图的高度
  • 将较小的图片放在与vbox较大图片具有相同高度的位置,并使用它vfill来获得所需的垂直对齐。

截屏

% arara: pdflatex
% !arara: indent: {overwrite: yes}
\documentclass{article}

\usepackage{subcaption}
\usepackage{tikz}
\usepackage{tikz-3dplot}

\newsavebox{\tempbox}
\begin{document}

\sbox{\tempbox}{%
    \tdplotsetmaincoords{60}{30}
    \begin{tikzpicture}[scale=1.55,tdplot_main_coords]
        \filldraw[
            draw=gray,
            fill=gray!40,
        ]          (1,0,1)
        -- (1,0,-1)
        -- (0,0,-1)
        -- (0,0,1)
        -- cycle;
        \draw[thin,->] (-1,0,0) -- (1,0,0) node[anchor=north east]{$x$};
        \draw[ultra thick] (0,0,-1) -- (0,0,1);
        \draw[ultra thick] (0,0,0) -- (1,0,0);
        \draw[thin,->] (0,-1,0) -- (0,1,0) node[anchor=north west]{$y$};
        \draw[thin,->] (0,0,-1) -- (0,0,1) node[anchor=south]{$z$};
    \end{tikzpicture}%
}


\begin{figure}[h]
    \centering
    \begin{subfigure}[b]{0.3\textwidth}
        \centering
        % for the other figures, you can use \vfill as follows
        \vbox to\ht\tempbox{
            \tdplotsetmaincoords{60}{30}
            \begin{tikzpicture}[scale=1.55,tdplot_main_coords]
                \filldraw[
                    draw=gray,
                    fill=gray!40,
                ]          (1,1,0)
                -- (0,1,0)
                -- (0,-1,0)
                -- (1,-1,0)
                -- cycle;
                \draw[thin,->] (-1,0,0) -- (1,0,0) node[anchor=north east]{$x$};
                \draw[ultra thick] (0,0,0) -- (0,1,0);
                \draw[ultra thick] (0,0,0) -- (1,0,0);
                \draw[ultra thick] (0,0,0) -- (0,-1,0);
                \draw[thin,->] (0,-1,0) -- (0,1,0) node[anchor=north west]{$y$};
                \draw[thin,->] (0,0,-1) -- (0,0,1) node[anchor=south]{$z$};
            \end{tikzpicture}
            \vfill
        }
        \caption{The cone $\sigma$}
    \end{subfigure}%
    \hfill
    \begin{subfigure}[b]{0.3\textwidth}
        \centering
        \usebox\tempbox
        \caption{The dual cone $\sigma^*$}
    \end{subfigure}
    \caption{$Cone((1,0,0),(0,1,0),(0,-1,0))$ and its dual cone.}
\end{figure}
\end{document}

相关内容