由於使用了 ,下面的 MWE 結果是虛假空間\tdplotsetmaincoords
:
紅色是邊界框,灰色框是來自\fbox{}
。
包括\unskip\unskip
(在 MWE 中註解掉)確實可以解決問題,但想知道是否有更好的解決方案。
這是一個錯誤還是有這個間距的原因?
筆記:
- 移動
\tdplotsetmaincoords{70}{115}
成為前\begin{document}
也解決了這個問題,但這對我來說並不容易,因為我的圖形使用該類別standalone
並包含在其他文件中 - 因此我需要將該設定與每個圖形進行本地化。
參考:
- 立方體繪製的程式碼來自如何用 TikZ 畫出一個所有面都有不同顏色的立方體?。
代碼:
\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}
答案1
代碼中存在虛假空格。通知維護者。
\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}