带有 pgfplot 虚线的网格线消失

带有 pgfplot 虚线的网格线消失

我想制作一个用于练习汉字(日语符号)的网格。我想要一个网格,其中每个单元格都用虚线分隔。如果一个单元格为 1 厘米或更大,效果会很好。但是,我希望每个单元格为 0.8 x0.8 厘米,如果我选择小于 1 厘米的任何东西,它都会编译,但尺寸不同,并且没有虚线。现在无法上传照片。它总是说 imgur 发生错误...

\documentclass[a4paper]{article}
\usepackage[margin=1cm]{geometry}
\usepackage[svgnames]{xcolor}
\usepackage{pgfplots}


\begin{document}
\thispagestyle{empty}
\pgfplotsset{minor grid style = {dashed, Gray}}
\pgfplotsset{major grid style = {solid, Black}}
    \begin{figure}\centering
        \begin{tikzpicture}[Black]
        \begin{axis}[grid = both,
                     ticks = none,
                     minor tick num = 1,
                     xmin = 0,
                     ymin = 0,
                     xmax = 17,
                     ymax = 26,
                     width = 17cm,
                     height = 26cm,
                     scale only axis]
        \end{axis}
        \end{tikzpicture}
    \end{figure}

    \newpage

    \pgfplotsset{minor grid style = {dashed, Black}}
\pgfplotsset{major grid style = {solid, Black}}
    \begin{figure}\centering
        \begin{tikzpicture}[Black]
       \begin{axis}[grid = both,
                 ticks = none,
                 minor tick num = 1,
                 xmin = 0,
                 ymin = 0,
                 xmax = 16,
                 ymax = 24,
                 xtick = {0, 0.8,..., 16},
                 ytick = {0, 0.8,..., 24},
                 width = 16cm,
                 height = 24cm,
                 scale only axis]
    \end{axis}
        \end{tikzpicture}
    \end{figure}




\end{document}

答案1

这样就够了吗?

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

\begin{document}
    \begin{tikzpicture}
        \draw[step=0.8cm,dashed] (0,0) grid (16,16);
    \end{tikzpicture}
\end{document}

编辑
我误解了你的问题,我读得太快了。

\documentclass[a4paper]{article}

\usepackage[margin=1cm]{geometry}
\usepackage{tikz}

\begin{document}
\thispagestyle{empty}
\noindent
\begin{tikzpicture}[scale=0.8]
    \draw[step=0.5,dashed,gray] (0,0) grid ++(23,34);
    \draw                       (0,0) grid ++(23,34);
\end{tikzpicture}
\end{document}

答案2

这是一个临时建议。使用scale。为了方便起见,此答案附带一个\ScaleFactor,设置为0.8但可以调整。

\documentclass[a4paper]{article}
\usepackage[margin=1cm]{geometry}
\usepackage[svgnames]{xcolor}
\usepackage{pgfplots}


\begin{document}
\thispagestyle{empty}
\pgfplotsset{minor grid style = {dashed, Gray}}
\pgfplotsset{major grid style = {solid, Black}}
    \begin{figure}\centering
        \begin{tikzpicture}[Black]
        \begin{axis}[grid = both,
                     ticks = none,
                     minor tick num = 1,
                     xmin = 0,
                     ymin = 0,
                     xmax = 17,
                     ymax = 26,
                     width = 17cm,
                     height = 26cm,
                     scale only axis]
        \end{axis}
        \end{tikzpicture}
    \end{figure}

    \newpage

    \pgfplotsset{minor grid style = {dashed, Black}}
\pgfmathsetmacro{\ScaleFactor}{0.8} 
\pgfplotsset{major grid style = {solid, Black}}
    \begin{figure}\centering
        \begin{tikzpicture}[Black,scale=\ScaleFactor]
       \begin{axis}[grid = both,
                 ticks = none,
                 minor tick num = 1,
                 xmin = 0,
                 ymin = 0,
                 xmax = 16/\ScaleFactor,
                 ymax = 24/\ScaleFactor,
                 width = 16cm/\ScaleFactor,
                 height = 24cm/\ScaleFactor,
                 scale only axis]
    \end{axis}
        \end{tikzpicture}
    \end{figure}
\end{document}

相关内容