如何绘制一个正方形及其带有箭头的对角线?

如何绘制一个正方形及其带有箭头的对角线?

在此处输入图片描述

我不知道如何绘制如上图所示的箭头,我为四个点编写的代码甚至没有显示在结果中。为什么我的点没有出现?箭头应该添加什么?

\documentclass{article}       
 \usepackage{tikz}     
 \begin{document}   
  \begin{tikzpicture}      
  \draw [fill=black](0, 0) circle;   
  \draw [fill=black](1, 0) circle;   
  \draw [fill=black](1, -1) circle;   
  \draw [fill=black](0, -1) circle;   
  \end{document}   

\documentclass{文章} \usepackage{tikz} \begin{文档} \begin{tikzpicture} \end{文档}

答案1

\documentclass{article}       
\usepackage{tikz}     
\begin{document}   
\begin{tikzpicture}
\node[circle, draw=black, fill=black, name=0] at (0,0) {};
\node[xshift=-2mm] at (0.west) {0};

\node[circle, draw=black, fill=black, name=1] at (0,1) {};
\node[xshift=-2mm] at (1.west) {1};

\node[circle, draw=black, fill=black, name=3] at (1,0) {};
\node[xshift=2mm] at (3.east) {3};

\node[circle, minimum width=1pt, draw=black, fill=black, name=2] at (1,1) {};
\node[xshift=2mm] at (2.east) {2};


\draw[->, blue] (0) -- (2);
\draw[->, blue] (0) -- (3);
\draw[->, blue] (0) -- (1);
\draw[->, blue] (1) -- (2);
\draw[->, blue] (1) -- (3);
\draw[->, blue] (2) -- (3);

\end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

PSTricks 解决方案:

\documentclass{article}

\usepackage{pst-node}

% parameters
\def\width{3}
\def\height{2}

% size of bounding box
\pstFPadd\Width{\width}{0.27}
\pstFPadd\Height{\height}{0.34}

\begin{document}

\begin{pspicture}(-0.27,-0.34)(\Width,\Height)
  \pnodes{P}(0,\height)(\width,\height)(\width,0)(0,0)
  \psdots(P0)(P1)(P2)(P3)
  \psset{arrows = ->, linecolor = cyan!80, nodesep = 1.5pt}
  \uput[135](P0){$0$}
  \uput[45](P1){$1$}
  \uput[315](P2){$2$}
  \uput[225](P3){$3$}
  \ncline{P0}{P1}
  \ncline{P1}{P2}
  \ncline{P2}{P3}
  \ncline{P0}{P3}
  \ncline{P0}{P2}
  \ncline{P1}{P3}
\end{pspicture}

\end{document}

输出

您所要做的就是改变参数的值,绘图就会进行相应的调整。

相关内容