[Tex/LaTex] 2D and 3D Tikz pictures side-by-side

floatstikz-3dplottikz-pgfvarwidth

Previously I've had problems with 3D Tikz pictures having a lot of whitespace added to one side which was solved by using \documentclass[varwidth,border=5pt]{standalone}.

Now, however, I'm trying to draw a 2D and 3D picture side-by-side. I can't just include the two pictures separately in the final document with the subcaption package because of journal graphics requirements. Previously I was generating two separate pdfs of the pictures, then combining them into one pdf (for insertion into the final document) with another .tex file. This seems like a convoluted way of doing things though.

Here's my MWE:

\documentclass[varwidth,border=5pt]{standalone}
\usepackage{tikz}
\usepackage{tikz-3dplot}

\usetikzlibrary{arrows}
\usetikzlibrary{3d}
\tikzset{>=latex}

\begin{document}

\begin{tikzpicture}

\draw[-] (0,0)--(3,0)--(3,2)--(0,2)--cycle;
\draw[-] (0,2)--(3,2)--(3,4)--(0,4)--cycle;
\draw[-] (0,4)--(3,4)--(3,6)--(0,6)--cycle;
\node at (-0.4,5.7) {{\large a}};

\end{tikzpicture}
\tdplotsetmaincoords{90}{90}
\tdplotsetrotatedcoords{0}{20}{70}
\begin{tikzpicture}[tdplot_rotated_coords]

\draw[->, thick] (0,0,0) --++ (20:3);
\draw[->] (0,0,0) --++ (60:2);

\draw[dashed] (0,0,-2) circle(2);
\draw[dashed] (0,0,0) circle(2);
\draw[dashed] (0,0,2) circle(2);

\node[left] at (0,0,0) {{ $i$}};
\node[right] at (2.2,0.15,-0.05) {{\large {\bf M}}};
\node[below] at (0.5,0.5,0) {{\large $\phi_i$}};

\draw[->] (0,0,-2) -- (0,0,3.5);
\node[above] at (0,0,3.5) {{\large $z$}};

\node at (-2,0,3.5) {{\large b}};

\end{tikzpicture}

\end{document}

If you compile it as it is, the two tikz pictures align one above the other. I think that's because of the varwidth argument. If you take that out the pictures are side-by-side but the whitespace associated with the 3D picture appears, so the two are separated by a large gap.

Does anyone know the best way around this?

Thanks.

Best Answer

2nd version:

So the problem seems to include different figures in one pdf file. There are several solutions but as you use standalone class and TiKZ you just need to include tikz as an option to your original example (\documentclass[tikz,varwidth,border=5pt]{standalone}) and will get a pdf file with as many pages as tikzpictures. You can include figures in your text with \includegraphics[page=...]{...}.

\documentclass{article}
\usepackage{subcaption}
\usepackage{graphicx}
\usepackage{lipsum}

\begin{document}

\begin{figure}
\begin{subfigure}{.5\linewidth}
\centering
\includegraphics[page=1]{sensetitol-3}
\subcaption{Subfigure}
\end{subfigure}
\begin{subfigure}{.5\linewidth}
\centering
\includegraphics[page=2]{sensetitol-3}
\subcaption{Subfigure}
\end{subfigure}
\end{figure}

\lipsum[2]
\end{document}

enter image description here

Original answer:

I don't understand the problem you have with the journalgraphics requirements but if you want to place both figures side by side with varwidth option one possible solution can be to draw both figures inside the same tikzpicture with one of them inside a properly placed scope.

Note: shift values have been found by trial and error.

\documentclass[varwidth,border=5pt]{standalone}
\usepackage{tikz}
\usepackage{tikz-3dplot}

\usetikzlibrary{arrows}
\usetikzlibrary{3d}
\tikzset{>=latex}

\begin{document}

\tdplotsetmaincoords{90}{90}
\tdplotsetrotatedcoords{0}{20}{70}
\begin{tikzpicture}

\draw[-] (0,0)--(3,0)--(3,2)--(0,2)--cycle;
\draw[-] (0,2)--(3,2)--(3,4)--(0,4)--cycle;
\draw[-] (0,4)--(3,4)--(3,6)--(0,6)--cycle;
\node at (-0.4,5.7) {{\large a}};
\begin{scope}[tdplot_rotated_coords, xshift=6cm, yshift=2.5cm]
\draw[->, thick] (0,0,0) --++ (20:3);
\draw[->] (0,0,0) --++ (60:2);

\draw[dashed] (0,0,-2) circle(2);
\draw[dashed] (0,0,0) circle(2);
\draw[dashed] (0,0,2) circle(2);

\node[left] at (0,0,0) {{ $i$}};
\node[right] at (2.2,0.15,-0.05) {{\large {\bf M}}};
\node[below] at (0.5,0.5,0) {{\large $\phi_i$}};

\draw[->] (0,0,-2) -- (0,0,3.5);
\node[above] at (0,0,3.5) {{\large $z$}};

\node at (-2,0,3.5) {{\large b}};
\end{scope}

\end{tikzpicture}
\end{document}

enter image description here