使用 TikZ 是否可以在两个绿色矩形之间绘制连接?这个想法是为了显示下方的绿色网格是上方网格的更详细视图。我也愿意接受其他想法 ;D
我目前的结果:
我想要的是将矩形的角与另一个矩形的相应角连接起来。
乳胶:
\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\pagestyle{empty}
\begin{tikzpicture}[scale=.9,every node/.style={minimum size=1cm},on grid]
\begin{scope}[ % Upper layer
yshift=90,every node/.append style={
yslant=0.5,xslant=-1},yslant=0.5,xslant=-1
]
\fill[white,fill opacity=.9] (0,0) rectangle (5,5);
\draw[step=10mm, green] (1,1) grid (4,4);
\draw[green,very thick] (1,1) rectangle (4,4);
\draw[black,dashed] (0,0) rectangle (5,5);
\end{scope}
\begin{scope}[ % Lower layer
yshift=170,every node/.append style={
yslant=0.5,xslant=-1},yslant=0.5,xslant=-1
]
\fill[white,fill opacity=0.6] (0,0) rectangle (5,5);
\draw[step=10mm, black] (2,2) grid (5,5);
\draw[step=3.33mm, green] (2,2) grid (3,3);
\draw[black,very thick] (2,2) rectangle (5,5);
\draw[black,dashed] (0,0) rectangle (5,5);
\draw[green,very thick] (2.05,2.05) rectangle (3,3);
\end{scope}
\end{tikzpicture}
\end{document}
答案1
首先,对于是否可以在两个绿色矩形之间建立连接的问题,我们给出一个直接的答案:可以。您可以使用 为第一个矩形角的坐标指定名称\coordinate
,这会在给定的坐标处创建节点。然后可以在第二个范围内引用这些节点:
\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\pagestyle{empty}
\begin{tikzpicture}[scale=.9,every node/.style={minimum size=1cm},on grid]
\begin{scope}[ % Upper layer
yshift=90,every node/.append style={
yslant=0.5,xslant=-1},yslant=0.5,xslant=-1
]
\fill[white,fill opacity=.9] (0,0) rectangle (5,5);
\draw[step=10mm, green] (1,1) grid (4,4);
\draw[green,very thick] (1,1) rectangle (4,4);
\draw[black,dashed] (0,0) rectangle (5,5);
\coordinate (A) at (1,1); \coordinate (B) at (1,4); \coordinate (C) at (4,1); \coordinate (D) at (4,4);
\end{scope}
\begin{scope}[ % Lower layer
yshift=170,every node/.append style={
yslant=0.5,xslant=-1},yslant=0.5,xslant=-1
]
\draw (A) -- (2.05,2.05) (B) -- (2.05,3) (C) -- (3,2.05) (D) -- (3,3);
\fill[white,fill opacity=0.6] (0,0) rectangle (5,5);
\draw[step=10mm, black] (2,2) grid (5,5);
\draw[step=3.33mm, green] (2,2) grid (3,3);
\draw[black,very thick] (2,2) rectangle (5,5);
\draw[black,dashed] (0,0) rectangle (5,5);
\draw[green,very thick] (2.05,2.05) rectangle (3,3);
\end{scope}
\end{tikzpicture}
\end{document}
关于“其他想法”:您还可以使用矩形节点代替路径,这样可以省去手动输入坐标的麻烦。为了使连接线位于顶部矩形后面,您可以使用图层。此外,我会将放大的矩形放在小比例矩形上方,稍微旋转所有内容,并使黑色网格变浅一点:
\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\pagestyle{empty}
\pgfdeclarelayer{bottom} \pgfdeclarelayer{top}
\pgfsetlayers{bottom,main,top}
\begin{tikzpicture}[scale=.9,every node/.style={minimum size=1cm},on grid]
\begin{pgfonlayer}{bottom}
\begin{scope}[ % Lower layer
yshift=0,every node/.append style={
yslant=0.5,xslant=-1,rotate=-10},yslant=0.5,xslant=-1,rotate=-10
]
\fill[white,fill opacity=0.9] (0,0) rectangle (5,5);
\draw[step=10mm, gray!70] (2,2) grid (5,5);
\draw[step=3.33mm, green] (2,2) grid (3,3);
\draw[gray,very thick] (2,2) rectangle (5,5);
\draw[black,dashed] (0,0) rectangle (5,5);
\node[name=B,draw,scale=0.9,green,very thick,text width=0.95,text height=0.95,inner sep=0pt,] at (2.525,2.525) {};
\end{scope}
\end{pgfonlayer}
\begin{scope}[ % Upper layer
yshift=105,every node/.append style={
yslant=0.5,xslant=-1,rotate=-10},yslant=0.5,xslant=-1,rotate=-10
]
\fill[white,fill opacity=.6] (0,0) rectangle (5,5);
\draw[step=10mm, green] (1,1) grid (4,4);
\node[scale=.9,draw,green,very thick,name=A,text width=3cm,text height=3cm,inner sep=0pt] at (2.5,2.5) {};
\draw[black,dashed] (0,0) rectangle (5,5);
\begin{pgfonlayer}{bottom}
\foreach \i in {north east,north west,south west,south east}
\draw (A.\i) -- (B.\i);
\end{pgfonlayer}
\end{scope}
\end{tikzpicture}
\end{document}
答案2
\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{intersections}
\begin{document}
\pagestyle{empty}
\begin{tikzpicture}[scale=.9,every node/.style={minimum size=1cm},on grid]
\begin{scope}[ % Upper layer
yshift=90,every node/.append style={
yslant=0.5,xslant=-1},yslant=0.5,xslant=-1
]
\fill[white,fill opacity=.9] (0,0) rectangle (5,5);
\draw[step=10mm, green] (1,1) grid (4,4);
\draw[green,very thick] (1,1) rectangle (4,4);
\draw[black,dashed,name path =rec1] (0,0) rectangle (5,5);
\coordinate (a) at (0,0);
\end{scope}
\begin{scope}[ % Lower layer
yshift=170,every node/.append style={
yslant=0.5,xslant=-1},yslant=0.5,xslant=-1
]
\fill[white,fill opacity=0.6] (0,0) rectangle (5,5);
\draw[step=10mm, black] (2,2) grid (5,5);
\draw[step=3.33mm, green] (2,2) grid (3,3);
\draw[black,very thick] (2,2) rectangle (5,5);
\draw[black,dashed,name path=rec2] (0,0) rectangle (5,5);
\draw[green,very thick] (2.05,2.05) rectangle (3,3);
\coordinate (b) at (2.05,2.05);
\end{scope}
\draw (a)--(b);
\end{tikzpicture}
\end{document}
对其他角也做同样的事情