1

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.

  • If you explain the problem with the journal, may be we can suggest better solutions – Ignasi Jan 15 '15 at 15:17
  • Copied from below for visibility: The problem with the journal is that they want all figures to be submitted as a single pdf file, even if they contain subfigures. So when I'd normally produce a pdf for each subfigure and put them both into the main document with \begin{figure}\begin{subfigure} etc., I'm having to join the two together so that only one pdf is included in the final document. Did it make sense that time? – thosphor Jan 15 '15 at 15:34
1

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

  • Wow that worked straight away, many thanks. The problem with the journal is that they want all figures to be submitted as a single pdf file, even if they contain subfigures. So when I'd normally produce a pdf for each subfigure and put them both into the main document with \begin{figure}\begin{subfigure} etc., I'm having to join the two together so that only one pdf is included in the final document. Did it make sense that time? – thosphor Jan 15 '15 at 15:23
  • @user3087409 See the edited answer, it can help you to produce all figures within one file – Ignasi Jan 15 '15 at 16:07
  • I didn't know about the [page= ... ] option, that's very useful. Thanks. – thosphor Jan 15 '15 at 16:10
1

You can put your pictures into two separate varwidth environments to do the trick:

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

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

\begin{document}

\begin{varwidth}{\linewidth}
\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}
\end{varwidth}
\begin{varwidth}{\linewidth}
\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{varwidth}

\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.