tikzpicture 不适合文档

tikzpicture 不适合文档

我有一段代码,我使用一些示波器来绘制一些 3D 图形。
但输出不适合独立文档。
\hbox{*}并且\vbox{*}没有帮助。

我需要做什么?

在此处输入图片描述

看起来应该是这样的:

在此处输入图片描述

\documentclass[margin=5pt]{standalone}
%\documentclass{article}
%\usepackage[margin=15mm]{geometry} 
\usepackage{tikz} 

\begin{document}

\def\a{1}
\def\h{0.2}
%%%%%%%%%%%%%%%%%%%%%%%%%%
\hbox{\vbox{%%%%%%%%%%%%%%%%%%%% 
%%%%%%%%%%%%%%%%%%%%%%%%%% 

\begin{tikzpicture}[font=\footnotesize,
very thin,
%line cap=round,
x={(1,0,0)}, z={(0,1,0)}, y={(0.5,0.5)}, 
every label/.style={text=black!1},
]

\coordinate[label=below:A] (A1) at (0,0,0);
\coordinate[label=below:B] (B1) at (\a,0,0);
\coordinate[label=below:C] (C1) at (\a,\a,0);
\coordinate[label=below:D] (D1) at (0,\a,0);
\coordinate[label=below:A] (A2) at (0,0,\h);
\coordinate[label=below:B] (B2) at (\a,0,\h);
\coordinate[label=below:C] (C2) at (\a,\a,\h);
\coordinate[label=below:D] (D2) at (0,\a,\h);

%% straight %%%%%%%%%%%%%%%%%%%%%
\foreach \n in {0,...,9}{%%
\begin{scope}[transform canvas={shift={(0,0,\n*\h)}}]
\draw[] (A1) -- (B1) -- (C1); 

\ifnum\n=9 \draw[fill=white] (A2) -- (B2) -- (C2) -- (D2) --cycle; 
\else \draw[fill=white] (A2) -- (B2) -- (C2);  \fi
\foreach \P in {A,B,C} \draw[] (\P1) -- (\P2);
\end{scope}
}%%

%% skew  %%%%%%%%%%%%%%%%%%%%%
\begin{scope}[transform canvas={shift={(12*\h+\a,0,0)}}]
\foreach \n in {0,...,9}{%%
\begin{scope}[transform canvas={shift={(-\n*\h,0,\n*\h)}}]
\draw[] (A1) -- (B1) -- (C1); 

\ifnum\n=9 \draw[fill=white] (A2) -- (B2) -- (C2) -- (D2) --cycle; 
\else \draw[fill=white] (A2) -- (B2) -- (C2) -- (D2);  \fi
\foreach \P in {A,B,C}{  \draw[] (\P1) -- (\P2);  }
\draw[fill=white] (B1) -- (C1) -- (C2) -- (B2) --cycle;
\end{scope}
}%%
\end{scope}
\end{tikzpicture}

%%%%%%%%%%%%%%%%%%%%%%%%%% 
}}%%%%%%%%%%%%%%%%%%%%%%%%% 
%%%%%%%%%%%%%%%%%%%%%%%%%% 
\end{document}

答案1

这是一种避免transform canvas每次使用坐标时添加转换的方法。

\documentclass[margin=5pt]{standalone}
\usepackage{tikz} 
% ateb: https://tex.stackexchange.com/a/707241/ addaswyd o gwestiwn cis: https://tex.stackexchange.com/q/707215/
\begin{document}

\begin{tikzpicture}[font=\footnotesize,
    very thin,
    x={(1,0,0)}, z={(0,1,0)}, y={(0.5,0.5)}, 
  ]
  \def\a{1}
  \def\h{0.2}
  \def\makecoords{%
    \coordinate (A1) at (0,0,0);
    \coordinate (B1) at (\a,0,0);
    \coordinate (C1) at (\a,\a,0);
    \coordinate (D1) at (0,\a,0);
    \coordinate (A2) at (0,0,\h);
    \coordinate (B2) at (\a,0,\h);
    \coordinate (C2) at (\a,\a,\h);
    \coordinate (D2) at (0,\a,\h);}
  %% straight %%%%%%%%%%%%%%%%%%%%%
  \foreach \n in {0,...,9}{%%
    \begin{scope}[shift={(0,0,\n*\h)}]
      \makecoords
      \draw (A1) -- (B1) -- (C1);
      \ifnum\n=9 \draw[fill=white] (A2) -- (B2) -- (C2) -- (D2) -- cycle; 
      \else \draw[fill=white] (A2) -- (B2) -- (C2);  \fi
      \foreach \P in {A,B,C} \draw[] (\P1) -- (\P2);
    \end{scope}
  }  
  %% skew  %%%%%%%%%%%%%%%%%%%%%
  \begin{scope}[shift={(12*\h+\a,0,0)}]
    \foreach \n in {0,...,9}{%%
      \begin{scope}[shift={(-\n*\h,0,\n*\h)}]
        \makecoords
        \draw[] (A1) -- (B1) -- (C1); 
        \ifnum\n=9 \draw[fill=white] (A2) -- (B2) -- (C2) -- (D2) --cycle; 
        \else \draw[fill=white] (A2) -- (B2) -- (C2) -- (D2);  \fi
        \foreach \P in {A,B,C}{  \draw[] (\P1) -- (\P2);  }
        \draw[fill=white] (B1) -- (C1) -- (C2) -- (B2) --cycle;
      \end{scope}
    }
  \end{scope}
\end{tikzpicture}
\end{document}

堆叠和阶梯式

我不确定这个\vboxin an\hbox是做什么用的,所以我把它删除了,因为它似乎没有任何作用。

相关内容