Tikz 图片的垂直对齐

Tikz 图片的垂直对齐

关于如何改善下面不同图的垂直对齐,您有什么想法吗?

在此处输入图片描述

由以下代码 MWE 制成:

\documentclass[a4paper]{article} % To avoid confusion, let us explicitly 
                             % declare the paper format.

\usepackage{multirow}
\usepackage[table,xcdraw]{xcolor}
\usepackage{float}
\usepackage{graphicx}
\usepackage{tikz}           %for TikZ graphics
\usepackage{tikz-3dplot} %for 3dplot functionality

\begin{document}

%harmonics.tex: produces spherical harmonic plots using the 3dplot package
% Author: Jeff Hein
\begin{figure}[H]
    \centering
    %Here's some more examples.
    \tdplotsetmaincoords{70}{135}
    \begin{tikzpicture}[scale=1,line join=bevel,tdplot_main_coords, fill opacity=.7]
    %L = 0
    \tdplotsphericalsurfaceplot[parametricfill]{72}{36}%
    {1}{black}{0}%
       {\draw[color=black,thick,->] (0,0,0) -- (2,0,0) node[anchor=north east]{$x$};}%
       {\draw[color=black,thick,->] (0,0,0) -- (0,2,0) node[anchor=north west]{$y$};}%
       {\draw[color=black,thick,->] (0,0,0) -- (0,0,2) node[anchor=south]{$z$};}%
    \end{tikzpicture}
    \begin{tikzpicture}[scale=1,line join=bevel,tdplot_main_coords, fill opacity=.7]
    %L = 1, M_L = -1
    \tdplotsphericalsurfaceplot[parametricfill]{72}{36}%
    {sqrt(3/2)*sin(\tdplottheta)}{black}{-\tdplotphi}%
       {\draw[color=black,thick,->] (0,0,0) -- (2,0,0) node[anchor=north east]{$x$};}%
       {\draw[color=black,thick,->] (0,0,0) -- (0,2,0) node[anchor=north west]{$y$};}%
       {\draw[color=black,thick,->] (0,0,0) -- (0,0,2) node[anchor=south]{$z$};}%
    \end{tikzpicture}
    \begin{tikzpicture}[scale=1,line join=bevel,tdplot_main_coords, fill opacity=.7]
    %L = 1, M_L = 0
    \tdplotsphericalsurfaceplot[parametricfill]{72}{36}%
    {sqrt(3)*cos(\tdplottheta)}{black}{0}%
       {\draw[color=black,thick,->] (0,0,0) -- (2,0,0) node[anchor=north east]{$x$};}%
       {\draw[color=black,thick,->] (0,0,0) -- (0,2,0) node[anchor=north west]{$y$};}%
       {\draw[color=black,thick,->] (0,0,0) -- (0,0,2) node[anchor=south]{$z$};}%
    \end{tikzpicture}
\end{figure}
\begin{figure}[H]
    \centering
    \tdplotsetmaincoords{70}{135}
    \begin{tikzpicture}[scale=1,line join=bevel,tdplot_main_coords, fill opacity=.7]
        %L = 1, M_L = +1
    \tdplotsphericalsurfaceplot[parametricfill]{72}{36}%
    {sqrt(3/2)*sin(\tdplottheta)}{black}{\tdplotphi}%
       {\draw[color=black,thick,->] (0,0,0) -- (2,0,0) node[anchor=north east]{$x$};}%
       {\draw[color=black,thick,->] (0,0,0) -- (0,2,0) node[anchor=north west]{$y$};}%
       {\draw[color=black,thick,->] (0,0,0) -- (0,0,2) node[anchor=south]{$z$};}%
    \end{tikzpicture}
    \begin{tikzpicture}[scale=1,line join=bevel,tdplot_main_coords, fill opacity=.7]
    %L = 2, M_L = -2
    \tdplotsphericalsurfaceplot[parametricfill]{72}{36}%
    {sqrt(15/2)/2*sin(\tdplottheta)^2}{black}{-2*\tdplotphi}%
       {\draw[color=black,thick,->] (0,0,0) -- (2,0,0) node[anchor=north east]{$x$};}%
       {\draw[color=black,thick,->] (0,0,0) -- (0,2,0) node[anchor=north west]{$y$};}%
       {\draw[color=black,thick,->] (0,0,0) -- (0,0,2) node[anchor=south]{$z$};}%
    \end{tikzpicture}
    \begin{tikzpicture}[scale=1,line join=bevel,tdplot_main_coords, fill opacity=.7]
    %L = 2, M_L = -1
    \tdplotsphericalsurfaceplot[parametricfill]{72}{36}%
    {sqrt(15/2)*sin(\tdplottheta)*cos(\tdplottheta)}{black}{-\tdplotphi}%
       {\draw[color=black,thick,->] (0,0,0) -- (2,0,0) node[anchor=north east]{$x$};}%
       {\draw[color=black,thick,->] (0,0,0) -- (0,2,0) node[anchor=north west]{$y$};}%
       {\draw[color=black,thick,->] (0,0,0) -- (0,0,2) node[anchor=south]{$z$};}%
    \end{tikzpicture}
\end{figure}

\begin{figure}[H]
    \centering
    \tdplotsetmaincoords{70}{135}
    \begin{tikzpicture}[scale=1,line join=bevel,tdplot_main_coords, fill opacity=.7]
    %L = 2, M_L = 0
    \tdplotsphericalsurfaceplot[parametricfill]{72}{36}%
    {sqrt(5)/2*(3*cos(\tdplottheta)^2 - 1 )}{black}{-\tdplotphi}%
       {\draw[color=black,thick,->] (0,0,0) -- (2,0,0) node[anchor=north east]{$x$};}%
       {\draw[color=black,thick,->] (0,0,0) -- (0,2,0) node[anchor=north west]{$y$};}%
       {\draw[color=black,thick,->] (0,0,0) -- (0,0,2) node[anchor=south]{$z$};}%
    \end{tikzpicture}
    \begin{tikzpicture}[scale=1,line join=bevel,tdplot_main_coords, fill opacity=.7]
    %L = 2, M_L = 1
    \tdplotsphericalsurfaceplot[parametricfill]{72}{36}%
    {sqrt(15/2)*sin(\tdplottheta)*cos(\tdplottheta)}{black}{\tdplotphi}%
       {\draw[color=black,thick,->] (0,0,0) -- (2,0,0) node[anchor=north east]{$x$};}%
       {\draw[color=black,thick,->] (0,0,0) -- (0,2,0) node[anchor=north west]{$y$};}%
       {\draw[color=black,thick,->] (0,0,0) -- (0,0,2) node[anchor=south]{$z$};}%
    \end{tikzpicture}
    \begin{tikzpicture}[scale=1,line join=bevel,tdplot_main_coords, fill opacity=.7]
    %L = 2, M_L = +2
    \tdplotsphericalsurfaceplot[parametricfill]{72}{36}%
    {sqrt(15/2)/2*sin(\tdplottheta)^2}{black}{2*\tdplotphi}%
       {\draw[color=black,thick,->] (0,0,0) -- (2,0,0) node[anchor=north east]{$x$};}%
       {\draw[color=black,thick,->] (0,0,0) -- (0,2,0) node[anchor=north west]{$y$};}%
       {\draw[color=black,thick,->] (0,0,0) -- (0,0,2) node[anchor=south]{$z$};}%
    \end{tikzpicture}
\end{figure}

\begin{figure}[H]
    \centering
    \tdplotsetmaincoords{70}{135}
    \begin{tikzpicture}[scale=1,line join=bevel,tdplot_main_coords, fill opacity=.7]
    %L = 3, M_L = 0
    \tdplotsphericalsurfaceplot[parametricfill]{72}{36}%
    {sqrt(7)/2*(5*cos(\tdplottheta)^3 - 3*cos(\tdplottheta))}{black}{0}%
       {\draw[color=black,thick,->] (0,0,0) -- (2,0,0) node[anchor=north east]{$x$};}%
       {\draw[color=black,thick,->] (0,0,0) -- (0,2,0) node[anchor=north west]{$y$};}%
       {\draw[color=black,thick,->] (0,0,0) -- (0,0,2) node[anchor=south]{$z$};}%
    \end{tikzpicture}
    \caption{Various spherical harmonics with TikZ}
\end{figure}

\end{document}

答案1

改编

  • 我将示例简化为前三个图。
  • 注意:你可以将所有图放入一个figure环境中
  • 定义命令\myboundingbox如下并在每个tikzpicture环境中使用它:
\useasboundingbox[draw=yellow] (2.5,0,-1.5) rectangle (0,2.5,3);
  • 选项draw=yellow仅用于测试,稍后可以删除
  • 定义mysphericalsurfaceplot为 tikz 样式以消除冗余

提示

如果你有许多这些计算量很大的图,使用外部化可能会有所帮助(请参阅如何将 TikZ 图片外部化):

\usetikzlibrary{external}
\tikzexternalize

结果

在此处输入图片描述

代码

\documentclass[a4paper]{article} % To avoid confusion, let us explicitly 
                             % declare the paper format.

\usepackage{multirow}
\usepackage[table,xcdraw]{xcolor}
\usepackage{float}
\usepackage{graphicx}
\usepackage{tikz}           %for TikZ graphics
\usepackage{tikz-3dplot} %for 3dplot functionality

%\usetikzlibrary{external}
%\tikzexternalize

\newcommand{\myboundingbox}{%
    \useasboundingbox[draw=yellow] (2.5,0,-1.5) rectangle (0,2.5,3);
}
\tikzset{
    mysphericalsurfaceplot/.style={scale=1,line join=bevel,tdplot_main_coords, fill opacity=.7}
}

\begin{document}

%harmonics.tex: produces spherical harmonic plots using the 3dplot package
% Author: Jeff Hein
\begin{figure}[htb]
    \centering
    %Here's some more examples.
    \tdplotsetmaincoords{70}{135}
    \begin{tikzpicture}[mysphericalsurfaceplot]
        \myboundingbox
        %L = 0
        \tdplotsphericalsurfaceplot[parametricfill]{72}{36}%
        {1}{black}{0}%
           {\draw[color=black,thick,->] (0,0,0) -- (2,0,0) node[anchor=north east]{$x$};}%
           {\draw[color=black,thick,->] (0,0,0) -- (0,2,0) node[anchor=north west]{$y$};}%
           {\draw[color=black,thick,->] (0,0,0) -- (0,0,2) node[anchor=south]{$z$};}%
    \end{tikzpicture}
    \begin{tikzpicture}[mysphericalsurfaceplot]
        \myboundingbox
        %L = 1, M_L = -1
        \tdplotsphericalsurfaceplot[parametricfill]{72}{36}%
        {sqrt(3/2)*sin(\tdplottheta)}{black}{-\tdplotphi}%
           {\draw[color=black,thick,->] (0,0,0) -- (2,0,0) node[anchor=north east]{$x$};}%
           {\draw[color=black,thick,->] (0,0,0) -- (0,2,0) node[anchor=north west]{$y$};}%
           {\draw[color=black,thick,->] (0,0,0) -- (0,0,2) node[anchor=south]{$z$};}%
    \end{tikzpicture}
    \begin{tikzpicture}[mysphericalsurfaceplot]
        \myboundingbox
        %L = 1, M_L = 0
        \tdplotsphericalsurfaceplot[parametricfill]{72}{36}%
        {sqrt(3)*cos(\tdplottheta)}{black}{0}%
           {\draw[color=black,thick,->] (0,0,0) -- (2,0,0) node[anchor=north east]{$x$};}%
           {\draw[color=black,thick,->] (0,0,0) -- (0,2,0) node[anchor=north west]{$y$};}%
           {\draw[color=black,thick,->] (0,0,0) -- (0,0,2) node[anchor=south]{$z$};}%
    \end{tikzpicture}
    \caption{Various spherical harmonics with TikZ}
\end{figure}

\end{document}

答案2

x您可以命名每个 tikzpicture 中用于对齐的节点。例如,可以通过插入(x)节点来命名 x 轴标签的节点:\draw[color=black,thick,->] (0,0,0) -- (2,0,0) node[anchor=north east](x){$x$};

然后添加baseline=(x)到每个 tikzpicture。

在此处输入图片描述

\documentclass[a4paper]{article} % To avoid confusion, let us explicitly 
                             % declare the paper format.
\usepackage{float}
\usepackage{graphicx}
\usepackage{tikz}           %for TikZ graphics
\usepackage{tikz-3dplot} %for 3dplot functionality

\begin{document}

%harmonics.tex: produces spherical harmonic plots using the 3dplot package
% Author: Jeff Hein
\begin{figure}[H]
    \centering
    %Here's some more examples.
    \tdplotsetmaincoords{70}{135}
    \begin{tikzpicture}[scale=1,line join=bevel,tdplot_main_coords, fill opacity=.7, baseline=(x)]
    %L = 0
    \tdplotsphericalsurfaceplot[parametricfill]{72}{36}%
    {1}{black}{0}%
       {\draw[color=black,thick,->] (0,0,0) -- (2,0,0) node[anchor=north east](x){$x$};}%
       {\draw[color=black,thick,->] (0,0,0) -- (0,2,0) node[anchor=north west]{$y$};}%
       {\draw[color=black,thick,->] (0,0,0) -- (0,0,2) node[anchor=south]{$z$};}%
    \end{tikzpicture}
    \begin{tikzpicture}[scale=1,line join=bevel,tdplot_main_coords, fill opacity=.7, baseline=(x)]
    %L = 1, M_L = -1
    \tdplotsphericalsurfaceplot[parametricfill]{72}{36}%
    {sqrt(3/2)*sin(\tdplottheta)}{black}{-\tdplotphi}%
       {\draw[color=black,thick,->] (0,0,0) -- (2,0,0) node[anchor=north east](x){$x$};}%
       {\draw[color=black,thick,->] (0,0,0) -- (0,2,0) node[anchor=north west]{$y$};}%
       {\draw[color=black,thick,->] (0,0,0) -- (0,0,2) node[anchor=south]{$z$};}%
    \end{tikzpicture}
    \begin{tikzpicture}[scale=1,line join=bevel,tdplot_main_coords, fill opacity=.7, baseline=(x)]
    %L = 1, M_L = 0
    \tdplotsphericalsurfaceplot[parametricfill]{72}{36}%
    {sqrt(3)*cos(\tdplottheta)}{black}{0}%
       {\draw[color=black,thick,->] (0,0,0) -- (2,0,0) node[anchor=north east](x){$x$};}%
       {\draw[color=black,thick,->] (0,0,0) -- (0,2,0) node[anchor=north west]{$y$};}%
       {\draw[color=black,thick,->] (0,0,0) -- (0,0,2) node[anchor=south]{$z$};}%
    \end{tikzpicture}
    \caption{Various spherical harmonics with TikZ}
\end{figure}

\end{document}

相关内容