![缩放的 TikZ 节点矩阵](https://linux22.com/image/361009/%E7%BC%A9%E6%94%BE%E7%9A%84%20TikZ%20%E8%8A%82%E7%82%B9%E7%9F%A9%E9%98%B5.png)
为了更好地记住学生的名字,我想制作我所教教室的示意图,以便学生可以勾选他们所坐的位置。使用一些想法这里我已经设计出了座位表,其中过道呈灰色(见下文)。
现在我想让它与房间尺寸成比例,使其更真实一些。例如,如果教室尺寸为 6m x 12m,房间顶部的开放区域为 4m,那么我想缩放座位矩阵以适合绘制的 6m x 12m 矩形内的 6m x 8m 区域。
我将非常感激任何帮助。然后我可以用老师的讲桌、讲台、门等来装饰房间轮廓。
非常感谢,帕特里克·希利
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\tikzset{myset/.style args = {(#1,#2)}{%
row #1 column #2/.style={nodes={circle,fill=gray}}}}
\begin{tikzpicture}[myset/.list={(1,3),(1,4),(2,3),(2,4),(3,3),(3,4),
(4,3),(4,4),(5,3),(5,4),(6,3),(6,4),(7,3),(7,4),
(8,3),(8,4),(8,1),(8,2),(8,3),(8,4),(8,5),(8,6),(8,7),(8,8)}]
\matrix [matrix of nodes, column sep=1mm, row sep=1mm, nodes={circle,draw}]
{
{}& {}& {}& {}& {}& {}& {}& {}\\
{}& {}& {}& {}& {}& {}& {}& {}\\
{}& {}& {}& {}& {}& {}& {}& {}\\
{}& {}& {}& {}& {}& {}& {}& {}\\
{}& {}& {}& {}& {}& {}& {}& {}\\
{}& {}& {}& {}& {}& {}& {}& {}\\
{}& {}& {}& {}& {}& {}& {}& {}\\
{}& {}& {}& {}& {}& {}& {}& {}\\
{}& {}& {}& {}& {}& {}& {}& {}\\
{}& {}& {}& {}& {}& {}& {}& {}\\
};
\end{tikzpicture}
\end{document}
答案1
也许这种scalerel
方法stackengine
对你有用。在这里,我将tikzpicture
(临时存储的\box0
)缩放到 8 厘米(实际上是 7.5 厘米),并将其和其他东西( 、、& )\stackinset
放置在 6 厘米 x 12 厘米中。\desk
\board
\lectern
\room
\documentclass{standalone}
\usepackage{tikz,scalerel,stackengine}
\setstackgap{S}{0pt}
\usetikzlibrary{matrix}
\setlength\unitlength{1cm}
\begin{document}
\tikzset{myset/.style args = {(#1,#2)}{%
row #1 column #2/.style={nodes={circle,fill=gray}}}}%
\setbox0=\hbox{\begin{tikzpicture}[myset/.list={(1,3),(1,4),(2,3),(2,4),(3,3),(3,4),
(4,3),(4,4),(5,3),(5,4),(6,3),(6,4),(7,3),(7,4),
(8,3),(8,4),(8,1),(8,2),(8,3),(8,4),(8,5),(8,6),(8,7),(8,8)}]
\matrix [matrix of nodes, column sep=1mm, row sep=1mm, nodes={circle,draw}]
{
{}& {}& {}& {}& {}& {}& {}& {}\\
{}& {}& {}& {}& {}& {}& {}& {}\\
{}& {}& {}& {}& {}& {}& {}& {}\\
{}& {}& {}& {}& {}& {}& {}& {}\\
{}& {}& {}& {}& {}& {}& {}& {}\\
{}& {}& {}& {}& {}& {}& {}& {}\\
{}& {}& {}& {}& {}& {}& {}& {}\\
{}& {}& {}& {}& {}& {}& {}& {}\\
{}& {}& {}& {}& {}& {}& {}& {}\\
{}& {}& {}& {}& {}& {}& {}& {}\\
};
\end{tikzpicture}}%
\savestack\studentdesks{\scaleto{\copy0}{7.5cm}}
\def\room{\rule{6cm}{0pt}\rule{0pt}{12cm}}%
\def\desk{\framebox(2.5,1.5){desk}}%
\def\lectern{\framebox(1,1){\tiny podium}}%
\def\board{\framebox(4,.2){\tiny board}}%
%
\stackinset{c}{}{t}{}{\board}{%
\stackinset{r}{.5cm}{t}{2.5cm}{\lectern}{%
\stackinset{l}{.5cm}{t}{1cm}{\desk}{%
\stackinset{c}{}{b}{}{\studentdesks}{%
\room}}}}%
\end{document}