我怎样才能将每个标签的背景填充为白色?

我怎样才能将每个标签的背景填充为白色?
 \documentclass {standalone}

 \usepackage[utf8]{inputenc}
 \usepackage{tikz}

 \begin{document}

   \begin{tikzpicture}[scale=0.5]
              \foreach \x in {0,1,2,3,...,6}{
         \draw (0,0) grid (6,6); 
       \node[black, fill=white, below] at (\x,3){\x}; 

 }


    \end{tikzpicture}
 \end{document}

该命令仅适用于最后一个标签 6 该命令仅适用于最后一个标签 6

如何阻止每个标签的重叠线?

答案1

先画网格:

\begin{tikzpicture}[scale=0.5]
  \draw (0,0) grid (6,6); 
  \foreach \x in {0,1,2,3,...,6}{
       \node[black, fill=white, below] at (\x,3){\x}; 
 }
\end{tikzpicture}

答案2

您正在绘制一个节点(带有白色背景),然后绘制网格,然后绘制其他节点,再次绘制网格,...这是因为您将网格里面\foreach如果你把网格放在前面,\foreach你就拥有了它。

\documentclass[tikz,border=2mm] {standalone}

\begin{document}
\begin{tikzpicture}[scale=0.5]
  \draw (0,0) grid (6,6); % outside the \foreach, we want to draw just one grid
  \foreach \x in {0,...,6}
    \node[black, fill=white, below] at (\x,3){\x}; 
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容