\begin{center}
\begin{tikzpicture}[x=7.5mm,y=4.34mm]
% some styles
\tikzset{
box/.style={
regular polygon,
regular polygon sides=6,
minimum size=10mm,
inner sep=0mm,
outer sep=0mm,
rotate=0,
draw
}
}
\foreach \i in {0,...,2}
\foreach \j in {0,...,2} {
\node[box] at (2*\i-1,2*\j-1) {};
\node[box] at (2*\i,2*\j) {};
}
\end{tikzpicture}
\end{center}
我在这段 LaTeX 代码中遇到了一些问题:
- 我想要 5 列,但这里有 6 列。
- 我只想要第一、第三和第五列中的 2 个六边形。
- 我希望第二行第二列和第四列的六边形为蓝色。并且我想在其中写入数字 1 和 3。
有人可以帮忙吗?提前谢谢了。
答案1
我不确定我是否理解了你的问题。你是指这样的吗?
\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{shapes.geometric}
\begin{document}
\begin{tikzpicture}[x=7.5mm,y=4.34mm,
every node/.style = {regular polygon, regular polygon sides=6, draw,
minimum size=10mm, inner sep=0mm, outer sep=0mm}
]
% rows
\foreach \i in {0,1,2}
{
\foreach \j in {0,1,2}
\node at (2*\j,-2*\i) {};
}
\foreach \j [count=\i from 0,
evaluate =\j as \k using int(\i+\j)] in {1,2}
{
\node at (2*\j-1,-3) {};
\node[draw=blue] at (2*\j-1,-1) {\k};
}
\end{tikzpicture}
\end{document}
答案2
只需删除最后一列即可获得正确的数字:
\begin{center}
\begin{tikzpicture}[x=7.5mm,y=4.34mm]
% some styles
\tikzset{
box/.style={
regular polygon,
regular polygon sides=6,
minimum size=10mm,
inner sep=0mm,
outer sep=0mm,
rotate=0,
draw
}
}
\foreach \i in {0,...,1}
\foreach \j in {0,...,2} {
\node[box] at (2*\i-1,2*\j-1) {};
\node[box] at (2*\i,2*\j) {};
}
\foreach \j in {0,...,2} {
\node[box] at (3,2*\j-1) {};
}
\end{tikzpicture}
\end{center}
答案3
代码仅在使用后编译
\usetikzlibrary{shapes.geometric}
虽然只有
\usetikzlibrary{shapes.geometry}
可以在下拉菜单中选择——并且代码不会编译geometry
那么这是一个错误吗?
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\begin{document}
\begin{tikzpicture}[x=7.5mm,y=4.34mm]
% some styles
\tikzset{
box/.style={
regular polygon,
regular polygon sides=6,
minimum size=10mm,
inner sep=0mm,
outer sep=0mm,
rotate=0,
draw
}
}
\foreach \i in {0,...,2}
\foreach \j in {0,...,2} {
\node[box] at (2*\i-1,2*\j-1) {};
\node[box] at (2*\i,2*\j) {};
}
\end{tikzpicture}
\end{document}