1

The MWE below results is spurious space due to the use of \tdplotsetmaincoords:

enter image description here

The red is the bounding box and the gray box is from \fbox{}.

Including an \unskip\unskip (commented out in the MWE) does resolve the problem, but wondering if there is a better solution.

Is this a bug or is there a reason for this spacing?

Notes:

  • Moving the \tdplotsetmaincoords{70}{115} to be before \begin{document} also resolves the problem, but this won't easily work for me as my figures use the standalone class and are included in other documents -- thus I need to have that setting localized with each figure.

References:

Code:

\documentclass{article}
\usepackage{tikz,tikz-3dplot}

\newcommand*{\DrawBoundingBox}[1][]{%
    \draw [
        draw=red, thick,
    ]
    ([shift={(-1pt,-1pt)}]current bounding box.south west) rectangle 
    ([shift={(1pt,1pt)}]current bounding box.north east);
}

\begin{document}
\fboxsep=0pt
\fbox{%
  %% code from https://tex.stackexchange.com/a/29342/4301
  \tdplotsetmaincoords{70}{115}%
  %\unskip\unskip% <----- HACK which fixes the problem.
  \begin{tikzpicture}[scale=4,tdplot_main_coords]
    \coordinate (O) at (0,0,0);
    \tdplotsetcoord{P}{1.414213}{54.68636}{45}

    \draw[fill=gray!50,fill opacity=0.5] (O) -- (Py) -- (Pyz) -- (Pz) -- cycle;
    \draw[fill=blue,fill opacity=0.5] (O) -- (Px) -- (Pxy) -- (Py) -- cycle;
    \draw[fill=yellow,fill opacity=0.5] (O) -- (Px) -- (Pxz) -- (Pz) -- cycle;
    \draw[fill=green,fill opacity=0.5] (Pz) -- (Pyz) -- (P) -- (Pxz) -- cycle;
    \draw[fill=red,fill opacity=0.5] (Px) -- (Pxy) -- (P) -- (Pxz) -- cycle;
    \draw[fill=magenta,fill opacity=0.5] (Py) -- (Pxy) -- (P) -- (Pyz) -- cycle;
    
    \DrawBoundingBox
  \end{tikzpicture}%
}%
\end{document}
2
  • 1
    It's unlikely that this will get fixed in tikz-3dplot. The last update was in 2012 and there are no contact details of the author in the manual. Mar 16, 2019 at 0:30
  • @HenriMenke After quick research, it seems I have found useful informations for contact the author of the tikz-3dplot package. From heinjd.wordpress.com/category/latex, I read in the bottom "Some time ago, I developed the 3dplot package". On heinjd.wordpress.com/about, I read "Jeff recently received a Ph.D. from the University of Manitoba Department of Physics and Astronomy." Finally, I found this JPL page: science.jpl.nasa.gov/people/Hein, with coordinate and CV. Correspond to the informations of the tikz-3dplot author.
    – quark67
    Mar 16, 2019 at 1:15

1 Answer 1

3

There are spurious spaces in the code. Notify the maintainer.

\documentclass{article}
\usepackage{tikz}
\usepackage{tikz-3dplot}

\newcommand*{\DrawBoundingBox}[1][]{%
    \draw [
        draw=red, thick,
    ]
    ([shift={(-1pt,-1pt)}]current bounding box.south west) rectangle
    ([shift={(1pt,1pt)}]current bounding box.north east);
}
\renewcommand{\tdplotsetmaincoords}[2]{%
%perform some trig for the display transformation
%
%
%store the user-specified angles for possible future use
\pgfmathsetmacro{\tdplotmaintheta}{#1}% <------ changed
\pgfmathsetmacro{\tdplotmainphi}{#2}% <------- changed
%
%
\tdplotcalctransformmainscreen
%
%now here is where the output is performed
\tikzset{tdplot_main_coords/.style={x={(\raarot cm,\rbarot cm)},y={(\rabrot cm, \rbbrot cm)},z={(\racrot cm, \rbcrot cm)}}}%
}

\begin{document}
\fboxsep=0pt 
\fbox{%
  %% code from https://tex.stackexchange.com/a/29342/4301
  \tdplotsetmaincoords{70}{115}%
  %\unskip\unskip% <----- HACK which fixes the problem.
  \begin{tikzpicture}[scale=4,tdplot_main_coords]
    \coordinate (O) at (0,0,0);
    \tdplotsetcoord{P}{1.414213}{54.68636}{45}

    \draw[fill=gray!50,fill opacity=0.5] (O) -- (Py) -- (Pyz) -- (Pz) -- cycle;
    \draw[fill=blue,fill opacity=0.5] (O) -- (Px) -- (Pxy) -- (Py) -- cycle;
    \draw[fill=yellow,fill opacity=0.5] (O) -- (Px) -- (Pxz) -- (Pz) -- cycle;
    \draw[fill=green,fill opacity=0.5] (Pz) -- (Pyz) -- (P) -- (Pxz) -- cycle;
    \draw[fill=red,fill opacity=0.5] (Px) -- (Pxy) -- (P) -- (Pxz) -- cycle;
    \draw[fill=magenta,fill opacity=0.5] (Py) -- (Pxy) -- (P) -- (Pyz) -- cycle;

    \DrawBoundingBox
  \end{tikzpicture}%
}%
\end{document}

enter image description here

2
  • Thanks. Good to know that it is an easy fix in the tikz-pgf code. Sadly have to wait a few minutes to accept the answer. Mar 16, 2019 at 0:16
  • 1
    the command is in tikz-3dplot, not tikz directly. Mar 16, 2019 at 0:19

You must log in to answer this question.

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