这是我目前所拥有的:
\documentclass[12pt]{article}
\usepackage{tikz}
\usepgflibrary{arrows}
\begin{document}
\begin{tikzpicture}
\node(1) at (0,0) [rectangle,draw]{};
\node at (0,-0.5) {$x_{j-1}$};
\node(2) at (2,0) [rectangle,draw]{};
\node at (2,-0.5) {$x_{j}$};
\node(3) at (4,0) [rectangle,draw]{};
\node at (4,-0.5) {$x_{j+1}$};
\node(4) at (6,0) [rectangle,draw]{};
\node at (6,-0.5) {$x_{j+2}$};
\node(5) at (8,0) [rectangle,draw]{};
\node at (8,-0.5) {$x_{j+3}$};
\node(6) at (0,2) [rectangle,draw]{};
\node(7) at (2,2.5) [rectangle,draw]{};
\node(8) at (4,2.3) [rectangle,draw]{};
\node(9) at (6,2.9) [rectangle,draw]{};
\node(10) at (8,2.7) [rectangle,draw]{};
\draw [<->](1) -- (2) node [midway,label=above:{$dx$}] {};
\draw (6) -- (7) -- (8) -- (9) -- (10);
\draw [->] (0,0) -- (xyz cs:x=1) node[above] {$x$};
\draw [->] (0,0) -- (xyz cs:y=1) node[right] {$f(x)$};
\end{tikzpicture}
\end{document}
结果如下:
不幸的是,我已将节点放置在坐标的左下角(0,0)
。这迫使坐标系与原点重合。如果我尝试将原点向上移动,如下所示:
\draw [->] (0,3) -- (xyz cs:x=1) node[above] {$x$};
\draw [->] (0,3) -- (xyz cs:y=1) node[right] {$f(x)$};
我得到了这样的情节:
如何在不失去其正交性的情况下将坐标系向上移动?
谢谢
答案1
我最终通过添加基于的范围来解决这个问题这个帖子
\documentclass[12pt]{article}
\usepackage{tikz}
\usepgflibrary{arrows}
\begin{document}
\begin{tikzpicture}
\node(1) at (0,0) [rectangle,draw]{};
\node at (0,-0.5) {$x_{j-1}$};
\node(2) at (2,0) [rectangle,draw]{};
\node at (2,-0.5) {$x_{j}$};
\node(3) at (4,0) [rectangle,draw]{};
\node at (4,-0.5) {$x_{j+1}$};
\node(4) at (6,0) [rectangle,draw]{};
\node at (6,-0.5) {$x_{j+2}$};
\node(5) at (8,0) [rectangle,draw]{};
\node at (8,-0.5) {$x_{j+3}$};
\node(6) at (0,2) [rectangle,draw]{};
\node at (0,2.5) {$f(x_{j-1})$};
\node(7) at (2,2.5) [rectangle,draw]{};
\node at (2,3.0) {$f(x_{j})$};
\node(8) at (4,2.3) [rectangle,draw]{};
\node at (4,2.8) {$f(x_{j+1})$};
\node(9) at (6,2.9) [rectangle,draw]{};
\node at (6,3.4) {$f(x_{j+2})$};
\node(10) at (8,2.7) [rectangle,draw]{};
\node at (8,3.2) {$f(x_{j+3})$};
\draw [<->](1) -- (2) node [midway,label=above:{$dx$}] {};
\draw (6) -- (7) -- (8) -- (9) -- (10);
\begin{scope}[shift={(0,4.2)}]
\draw [->] (0,0) -- (xyz cs:x=1) node[above] {$x$};
\draw [->] (0,0) -- (xyz cs:y=1) node[right] {$f(x)$};
\end{scope}
\end{tikzpicture}
\end{document}
答案2
最明显的做法当然是指定端点的正确坐标,例如(xyz cs:x=1,y=3)
x 轴的坐标为。(我不太明白为什么不使用 eg(1,3)
而使用xyz cs:
,但那是另一回事。)
另一种可能更方便的选择是使用相对坐标,例如
\draw [->] (0,3) -- +(1,0) node[above] {$x$};
\draw [->] (0,3) -- +(0,1) node[right] {$f(x)$};
表示+
相(1,0)
对于前一个坐标 ( (0,3)
)。
\documentclass[12pt]{article}
\usepackage{tikz}
\usepgflibrary{arrows}
\begin{document}
\begin{tikzpicture}
\node(1) at (0,0) [rectangle,draw]{};
\node at (0,-0.5) {$x_{j-1}$};
\node(2) at (2,0) [rectangle,draw]{};
\node at (2,-0.5) {$x_{j}$};
\node(3) at (4,0) [rectangle,draw]{};
\node at (4,-0.5) {$x_{j+1}$};
\node(4) at (6,0) [rectangle,draw]{};
\node at (6,-0.5) {$x_{j+2}$};
\node(5) at (8,0) [rectangle,draw]{};
\node at (8,-0.5) {$x_{j+3}$};
\node(6) at (0,2) [rectangle,draw]{};
\node(7) at (2,2.5) [rectangle,draw]{};
\node(8) at (4,2.3) [rectangle,draw]{};
\node(9) at (6,2.9) [rectangle,draw]{};
\node(10) at (8,2.7) [rectangle,draw]{};
\draw [<->](1) -- (2) node [midway,label=above:{$dx$}] {};
\draw (6) -- (7) -- (8) -- (9) -- (10);
% option 1
%\draw [->] (0,3) -- (xyz cs:x=1,y=3) node[above] {$x$};
%\draw [->] (0,3) -- (xyz cs:y=4) node[right] {$f(x)$};
% option 2
%\draw [->] (0,3) -- (1,3) node[above] {$x$};
%\draw [->] (0,3) -- (0,4) node[right] {$f(x)$};
% option 3
\draw [->] (0,3) -- +(1,0) node[above] {$x$};
\draw [->] (0,3) -- +(0,1) node[right] {$f(x)$};
\end{tikzpicture}
\end{document}