5

Any idea on how i can improve the vertical alignement of the different plots below?

enter image description here

Made from the following code 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}

2 Answers 2

2

Adaptations

  • I reduced the example to the first three plots.
  • Note: You can put all plots into a single figure environment
  • defined command \myboundingbox as follows and used it in every tikzpicture environment:
\useasboundingbox[draw=yellow] (2.5,0,-1.5) rectangle (0,2.5,3);
  • option draw=yellow is only for testing and can be removed later
  • defined mysphericalsurfaceplot as tikz style to remove redundancies

Tip

If you have many of these computationally expensive plots, it might be beneficial to use externalization (see How to externalize TikZ pictures):

\usetikzlibrary{external}
\tikzexternalize

Result

enter image description here

Code

\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

You can name a node that you will use for alignment in each tikzpicture. For example, the node for the x-axis label could be named x by inserting (x) into the node: \draw[color=black,thick,->] (0,0,0) -- (2,0,0) node[anchor=north east](x){$x$};

Then add baseline=(x) to each tikzpicture.

enter image description here

\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}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .