答案1
\documentclass{article}
\usepackage{tikz}
\usepackage{amsmath}
\begin{document}
\begin{tikzpicture}
\draw[thin,gray!40] (-2,-2) grid (2,2);
\draw[<->] (-2,0)--(2,0) node[right]{$x$};
\draw[<->] (0,-2)--(0,2) node[above]{$y$};
\draw[line width=2pt,blue,-stealth](0,0)--(1,1) node[anchor=south west]{$\boldsymbol{u}$};
\draw[line width=2pt,red,-stealth](0,0)--(-1,-1) node[anchor=north east]{$\boldsymbol{-u}$};
\end{tikzpicture}
\end{document}
答案2
另一个简单的解决方案是(如果您使用MiKTeX、TeX Live 和 MacTeX的开关pstricks
,则可以编译):pdflatex
--enable-write18
-shell-escape
\documentclass[svgnames, border=3pt]{standalone}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{pst-plot}
\usepackage{auto-pst-pdf}
\begin{document}
\psset{arrowinset=0.12, labels = none, ticks=none, fillstyle=solid}
\begin{pspicture}%
\psgrid[gridlabels=0pt, gridwidth=0.3pt, gridcolor=LightSteelBlue, subgriddiv=1, subgridwidth=0pt](-2,-2)(2,2)
\psaxes[arrows=<->] (0,0)(-2,-2)(2,2)
\psset{arrows=->}
\psline[linecolor=SteelBlue, linewidth=1.8pt](0,0)(1,1)
\uput[r](1,1){$\color{SteelBlue}\mathbf{u}$}
\psline[linecolor=IndianRed, linewidth=1.8pt](0,0)(-1,-1)
\uput[l](-1,-1){$\color{IndianRed}\mathbf{-u}$}
\end{pspicture}
\end{document}