网格和绘制使用不同的坐标?

网格和绘制使用不同的坐标?

使用这个 MWE 可以很容易地解释这个问题:

\documentclass{standalone}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
 \draw [very thin, color=gray, dashed] (0, 0) grid (5, 5);
 \draw [color=green!50!black, ->] (0, 0) -- (3,3)  node[above right]{$\vec{A}$};
 \draw (0,5) node[below right]{graph 1};
\end{tikzpicture}
\begin{tikzpicture}[x=0.5cm, y=0.5cm]
 \draw [very thin, color=gray, dashed] (0, 0) grid (5, 5);
 \draw [color=green!50!black, ->] (0, 0) -- (3,3)  node[above right]{$\vec{A}$};
 \draw (0,5) node[below right]{graph 2};
\end{tikzpicture}
\begin{tikzpicture}[scale=0.5]
 \draw [very thin, color=gray, dashed] (0, 0) grid (5, 5);
 \draw [color=green!50!black, ->] (0, 0) -- (3,3)  node[above right]{$\vec{A}$};
 \draw (0,5) node[below right]{graph 3};
\end{tikzpicture}
\end{document}

结果是:

mwe 之前的结果

在输出中,graph2确实让我很惊讶 --- 似乎grid--绘制线条的使用了不同的坐标。我原本以为网格会随着线条的缩小而缩小……我遗漏了什么?

(顺便说一句 --- 而且两张图表中的文本都没有缩小,这一点相当令人惊讶)。

答案1

一切都很好,点 A 是 (3,3),因为 (1,1) 位于 (0.5cm,0.5cm),您可以像这样设置 step=1

\documentclass{standalone}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
 \draw [very thin, color=gray, dashed] (0, 0) grid (5, 5);
 \draw [color=green!50!black, ->] (0, 0) -- (3,3)  node[above right]{$\vec{A}$};
 \draw (0,5) node[below right]{graph 1};
\end{tikzpicture}
\begin{tikzpicture}[x=0.5cm, y=0.5cm]
 \draw [very thin, color=gray, dashed, step=1] (0, 0) grid (5, 5);  % ---> step=1
 \draw [color=green!50!black, ->] (0, 0) -- (3,3)  node[above right]{$\vec{A}$};
 \draw (0,5) node[below right]{graph 2};
\end{tikzpicture}
\begin{tikzpicture}[scale=0.5]
 \draw [very thin, color=gray, dashed] (0, 0) grid (5, 5);
 \draw [color=green!50!black, ->] (0, 0) -- (3,3)  node[above right]{$\vec{A}$};
 \draw (0,5) node[below right]{graph 3};
\end{tikzpicture}
\end{document} 

编辑:对于文本缩放,你可以看到如何缩放包含文本的 tikzpicture?

在此处输入图片描述

编辑关于网格(这只是第一张 tikzpicture)

\documentclass{standalone}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
 \draw [very thin, color=gray, dashed] (0, 0) grid (5, 5);
 \draw [color=green!50!black, ->] (0, 0) -- (3,3)  node[above right]{$\vec{A}$};
 \draw (0,5) node[below right]{graph 1};
\end{tikzpicture}

\begin{tikzpicture}
 \draw [very thin, color=gray, dashed,step=0.5] (0, 0) grid (5, 5);
 \draw [color=green!50!black, ->] (0, 0) -- (3,3)  node[above right]{$\vec{A}$};
 \draw (0,5) node[below right]{graph 1};
\end{tikzpicture}

\begin{tikzpicture}
 \draw [very thin, color=gray, dashed,step=0.2] (0, 0) grid (5, 5);
 \draw [color=green!50!black, ->] (0, 0) -- (3,3)  node[above right]{$\vec{A}$};
 \draw (0,5) node[below right]{graph 1};
\end{tikzpicture}
\end{document} 

在此处输入图片描述

相关内容