TikZ 中的空间节省和循环

TikZ 中的空间节省和循环

下面的源/输出对(用于 Hex 游戏列表)存在两个主要问题:

1) 至少在我的打印输出中,有一个不必要的左边距和顶部边距(我不知道它们来自哪里)所以右侧和底部被吃掉了。

2)我的丑陋的11行代码片段,其意图是abc- ... -k上的循环,肯定可以用一行智能循环代替吗?

关于如何解决这些问题有什么想法吗?

\documentclass{article}
\usepackage{amssymb}
\usepackage{mathrsfs}
\usepackage{pifont}
\usepackage{xcolor}
\usepackage{tikz}
\usepackage[a4paper,nohead,nofoot]{geometry}

\addtolength{\textwidth}{4cm}
\addtolength{\textheight}{4cm}

\addtolength{\hoffset}{-2cm}
\addtolength{\voffset}{-2cm} 


\begin{document}

\pagestyle{empty}

\begin{tikzpicture}
\path (-1,0) coordinate (Z);
\path (Z)++(0.2,0) coordinate (Y);
\foreach \bx in {0,5.5,11,16.5}
{
\foreach \by in {0,-6,-12,-18,-24}
{
\path (Y) ++(\bx,\by)  coordinate (X);

\draw (X)  ++(0.2,0.2) node[anchor=south east] {$a$};
\draw (X)  ++(0.6,0.2) node[anchor=south east] {$b$};
\draw (X)  ++(1.0,0.2) node[anchor=south east] {$c$};
\draw (X)  ++(1.4,0.2) node[anchor=south east] {$d$};
\draw (X)  ++(1.8,0.2) node[anchor=south east] {$e$};
\draw (X)  ++(2.2,0.2) node[anchor=south east] {$f$};
\draw (X)  ++(2.6,0.2) node[anchor=south east] {$g$};
\draw (X)  ++(3.0,0.2) node[anchor=south east] {$h$};
\draw (X)  ++(3.4,0.2) node[anchor=south east] {$i$};
\draw (X)  ++(3.8,0.2) node[anchor=south east] {$j$};
\draw (X)  ++(4.2,0.2) node[anchor=south east] {$k$};
\foreach \x in {1,2,...,11}
{
\draw (X)++(\x*0.2,-\x*0.4) ++(-0.2,0.4) node[anchor=east] {$\x$};
\foreach \y in {0,0.2,...,2}
{
\draw (X) ++(-0.4,0) ++(\x*0.4,0) ++(\y,-\y*2)  -- ++(0,0.2) -- ++(0.2,0.2) -- ++(0.2,-0.2)  -- ++(0,-0.2) -- ++(-0.2,-0.2) --cycle;
}
}
}
}


\end{tikzpicture}


\end{document}

在此处输入图片描述

答案1

作为记录,这里是根据薛定谔的猫评论中的建议进行的修复:

\documentclass{article}
\usepackage{amssymb}
\usepackage{mathrsfs}
\usepackage{pifont}
\usepackage{xcolor}
\usepackage{tikz}
\usepackage[a4paper,nohead,nofoot,margin=0pt]{geometry}
\begin{document}
\pagestyle{empty}
\begin{tikzpicture}
\path (-1,0) coordinate (Z);
\path (Z)++(0.2,0) coordinate (Y);
\foreach \bx in {0,5.5,11}
{
\foreach \by in {0,-6,-12,-18,-24}
{
\path (Y) ++(\bx,\by)  coordinate (X);
\foreach \Label [count=\X] in {a,...,k} {\draw (X) ++(-0.2+\X*0.4,0.2) node[anchor=south east] {$\Label$};}
\foreach \x in {1,2,...,11}
{
\draw (X)++(\x*0.2,-\x*0.4) ++(-0.2,0.4) node[anchor=east] {$\x$};
\foreach \y in {0,0.2,...,2}
{
\draw (X) ++(-0.4,0) ++(\x*0.4,0) ++(\y,-\y*2)  -- ++(0,0.2) -- ++(0.2,0.2) -- ++(0.2,-0.2)  -- ++(0,-0.2) -- ++(-0.2,-0.2) --cycle;
}}}}
\end{tikzpicture}
\end{document}

相关内容