
我想繪製幾張複雜的繪圖並將它們全部放在一個更大的 TikZ 繪圖中。我怎麼做?
到目前為止,這就是我所做的:
\documentclass[preview]{standalone}
\begin{document}
\begin{tikzpicture}
\draw[help lines] (0,0) grid (10, 10);
\node (rectifier) at (0,0) {
\begin{tikzpicture}
\node (sine) at (1.25,3) {
\begin{tikzpicture}[scale=0.4]
\draw (0,0) sin (1,1) cos (2,0) sin (3,-1) cos (4,0);
\end{tikzpicture}
};
\node (rect) at (2.75,1) {
\begin{tikzpicture}[scale=0.4]
\draw (0,2) sin ++(1,1) cos (2,2) sin (3,3) cos (4,2) ;
\end{tikzpicture}
};
\draw (0,0) rectangle (4,4) -- (0,0);
\end{tikzpicture}
};
\end{tikzpicture}
\end{document}
問題:
我希望整個(rectifier)
盒子及其所有內容都可以從頂層進行擴展,如下所示:
\node (rectifier) at (0,0) {
\begin{tikzpicture}[scale=0.5]
...
...
...
但它只縮放盒子,而不縮放正弦圖。
擴大:
TikZ 中是否存在「物件導向」範例,我可以在其中聲明物件類別並在更大的繪圖中簡單地實例化它們?
答案1
首先,您將圖片放置在節點內。雖然這很有效,而且在很多時候這是必須做的,但當必須應用轉換時,使用它是很微妙的。
第二項,從概念上講,您的圖表似乎是處於同一「等級」的事物,只是位於不同的位置。範圍環境更適合您想要的。
第三件事是的,tikz中有物件導向的結構。我不使用它(從這個網站上的大多數答案來看,大多數人不使用它)。您可以在手冊中找到資訊。
使用範圍的程式碼版本是:
\documentclass[preview]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw[help lines] (0,0) grid (10, 10);
\begin{scope}[scale=0.5]
\draw[green,shift={(1.25,3)}] (0,0) sin (1,1) cos (2,0) sin (3,-1) cos (4,0);
\draw[blue,shift={(2.75,1)}] (0,2) sin ++(1,1) cos (2,2) sin (3,3) cos (4,2) ;
\draw (0,0) rectangle (4,4) -- (0,0);
\end{scope}
%The same stuff, but shifted, to show you can shift a whole picture
\begin{scope}[scale=0.5,shift={(5,5)}]
\draw[green,shift={(1.25,3)}] (0,0) sin (1,1) cos (2,0) sin (3,-1) cos (4,0);
\draw[blue,shift={(2.75,1)}] (0,2) sin ++(1,1) cos (2,2) sin (3,3) cos (4,2) ;
\draw (0,0) rectangle (4,4) -- (0,0);
\end{scope}
\end{tikzpicture}
\end{document}