
我有一個程式碼,我使用一些範圍來繪製一些 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}
我不確定\vbox
in an 的\hbox
用途,所以我將其刪除,因為它似乎沒有任何功能。