我想在结构课程的框架中沿着一些线绘制一个坐标系。这个小坐标系称为局部坐标系。
目前框架如下所示:
\documentclass{article} % say
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}[scale=1,inner sep=0pt,thick,dot/.style={draw,circle,minimum size=4pt}]
\draw [help lines] (0,0) grid (3,4);
\node[dot] (2) at (0,0) [label={[label distance=1mm]270:2}] {};
\node[dot] (3) at (0,2) [label={[label distance=1mm]180:3}] {};
\node[dot] (1) at (0,4) [label={[label distance=1mm]90:1}] {};
\node[dot] (4) at (3,2) [label={[label distance=1mm]0:4}] {};
\node[dot] (5) at (2.5,4) [label={[label distance=1mm]45:5}] {};
\draw (2) -- (3) node [midway,sloped,below] {3};
\draw (3) -- (4) node [midway,above,sloped] {4};
\draw (2) -- (4) node [midway,above,sloped] {6};
%\draw [<->] (0,0.8) -- (0,0) -- (0.8,0);
%\draw[->] (-.1,1) -- (-.6,1) node[right] {$y$} coordinate(y axis);
%\draw[->] (-.1,1) -- (-.1,1.5) node {$x$} coordinate(x axis);
\end{tikzpicture}
\end{document}
我想要这样的东西:
但我不知道该怎么做。有人知道吗?我该如何在行上的数字之间留出一些空间?
答案1
一种可能性是使用markings
装饰。也可以定义镜像情况,使其位于线下或可以显示用户提供的额外选项,但想法本质上是一样的。
\documentclass[tikz]{standalone}
\usetikzlibrary{calc,decorations.markings}
\begin{document}
\begin{tikzpicture}[scale=1,inner sep=0pt,thick,dot/.style={draw,circle,minimum size=4pt},
put coord sys/.style={
decoration={markings,
mark= at position 0.5
with
{
\draw[latex-latex,ultra thin] (2pt,2pt) +(5mm,0) -| +(0,5mm)
node[above right,rotate=\pgfdecoratedangle] {$\scriptstyle y$};
\path (2pt+5mm,2pt)
node[above right,rotate=\pgfdecoratedangle] {$\scriptstyle x$};
}
},
postaction=decorate}]
\draw [help lines] (0,0) grid (3,4);
\node[dot] (2) at (0,0) [label={[label distance=1mm]270:2}] {};
\node[dot] (3) at (0,2) [label={[label distance=1mm]180:3}] {};
\node[dot] (1) at (0,4) [label={[label distance=1mm]90:1}] {};
\node[dot] (4) at (3,2) [label={[label distance=1mm]0:4}] {};
\node[dot] (5) at (2.5,4) [label={[label distance=1mm]45:5}] {};
\draw[put coord sys] (2) -- (3);
\draw[put coord sys] (3) -- (4);
\draw[put coord sys] (2) -- (4);
\end{tikzpicture}
\end{document}
答案2
使用 PSTricks:
\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pst-plot}
\psset{labels=none,ticks=none,arrows=->}
\begin{document}
\begin{pspicture}[showgrid=true](5,5)
\rput{30}(2,2){\psaxes(0,0)(-1,-1)(2,2)[$x$,0][$y$,90]}
\end{pspicture}
\end{document}
解释:
\psset{labels=none,ticks=none,arrows=->}
设置没有标签、没有刻度但有指向上方和右侧的箭头的轴。\psaxes(0,0)(-1,-1)(2,2)[$x$,0][$y$,90]
绘制轴和轴名称。\rput{30}(2,2){...}
旋转和平移轴。
各种各样的:
\documentclass[pstricks,border=15pt]{standalone}
\usepackage{pst-plot,pst-eucl}
\psset{labels=none,ticks=none,arrows=->,saveNodeCoors}
\addtopsstyle{gridstyle}{gridlabels=0pt}
\begin{document}
\begin{pspicture}[showgrid=true](5,4)
\pstGeonode[CurveType=polygon,PointName=none](0,0){A}(5,3){B}(0,3){C}
\rput{!N-B.y N-B.x atan}(2.3,1.6){\psaxes[linecolor=blue](0,0)(1,1)[$x$,0][$y$,90]}
\end{pspicture}
\end{document}