
일부 범위를 사용하여 일부 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
아무 기능도 하지 않는 것 같아서 제거했습니다.