\documentclass[tikz,border95=3mm]{article}
\usepackage{tikz}
\usepackage{xcolor}
\begin{document}
\begin{tikzpicture}[case/.style={minimum width=2cm,minimum height=2cm,draw},line/.style={blue!10!gray,line width=4,line cap=round,line join=round}]
\node[case] (a) at (0,0){} ;
\node[case] (b) at (2,0){} ;
\node[case] (c) at (0,2){} ;
\node[case] (d) at (2,2){} ;
\draw[line] (c.south west) -- (c.north west) -- (c.north east) -- (c.south west)-- ++(-1,-1);
\draw[line] (c.south west) -- (c.south east) -- (c.north east) -- (d.north east)-- (a.south west) -- ++(-1,-1);
\draw[line] (d.north east) -- (b.north east) -- (b.north west) -- (b.south west)-- (a.south west) -- (a.north west);
\draw[line] (b.south west) -- (b.south east) -- (b.north east) -- (b.south west)-- ++(-1.25,-1.25);
\node[left=0.5 cm,above] at (a) {\huge 2};
\node[above=0.25 cm] at (c.north) {\huge 4};
\node[above=0.25 cm] at (d.north) {\huge 5};
\node[text=green,shift={(0.5,0.5)}] at (d.north east) { \huge $\times$};
\end{tikzpicture}
\end{document}
我不习惯在 TikZ 中使用节点和定位,我已经阅读了 Latex Draw 教程,但无法将其制作成 3 乘 1 的网格,有什么帮助吗?
答案1
像这样吗?
\documentclass[tikz,border95=3mm]{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[case/.style={minimum width=2cm,minimum height=2cm,draw},line/.style={blue!10!gray,line width=4,line cap=round,line join=round}]
\node[case] (a) at (0,0){} ;
\node[case] (b) at (2,0){} ;
\node[case] (c) at (4,0){} ;
%\node[case] (d) at (2,2){} ;
\draw[line] (a.south west) -- (a.north west) -- (a.north east) -- (a.south west)-- ++(-1,-1);
\draw[line] (b.south west) -- (b.north west) -- (b.north east) -- (b.south west)-- ++(-1,-1);
\draw[line] (c.south west) -- (c.north west) -- (c.north east) -- (c.south west)-- ++(-1,-1);
\draw[line] (a.south west) -- (c.south east) -- (c.north east);
\node[above=0.25 cm] at (a.north) {\huge a};
\node[above=0.25 cm] at (b.north) {\huge b};
\node[above=0.25 cm] at (c.north) {\huge c};
\end{tikzpicture}
\end{document}
答案2
还有另一种可能性:
\documentclass[tikz]{standalone}
\usetikzlibrary{calc}
\begin{document}
% size of the squares: 1x1
\begin{tikzpicture}[
line/.style={
blue!10!gray,
line width=4
}
]
% border
\draw[line] (0,1) rectangle (3,0);
% vertical lines
\foreach \x in {1,2} {
\draw[line] (\x,0) -- (\x,1);
}
% oblique lines
\foreach \i in {1,2,3} {
\draw[line] (\i,1) -- (\i-2,-1);
}
% place the nodes a, b and c
\foreach \nodeText [count=\c] in {a,b,c} {
\node[font=\huge, anchor=mid] at (\c-.5,1.3) {\nodeText};
}
\end{tikzpicture}
% size of the squares: 2x2
\begin{tikzpicture}[
line/.style={
blue!10!gray,
line width=4
}
]
% border
\draw[line] (0,2) rectangle (6,0);
% vertical lines
\foreach \x in {2,4} {
\draw[line] (\x,0) -- (\x,2);
}
% oblique lines
\foreach \i in {2,4,6} {
\draw[line] (\i,2) -- (\i-3,-1);
}
% place the nodes a, b and c
\foreach \nodeText [count=\c] in {a,b,c} {
\node[font=\huge, anchor=mid] at (\c*2-1,2.3) {\nodeText};
}
\end{tikzpicture}
\end{document}