
我有以下兩個問題。
首先我要告訴大家的是,我提供的 MWE 部分是根據 geogebra 編輯的。
問題:1 在此圖中,我想在所有四個邊上添加方向(如 >)。
問題:2 還有其他方法可以繪製相同的圖形嗎?因為我想學習新的繪畫技巧。
微量元素:
\documentclass{article}
\usepackage{tikz}
\usepackage{pgf}
\usepackage{pgfplots}
\usetikzlibrary{arrows}
\begin{document}
\begin{tikzpicture}
\draw [line width=1pt] (0,0)-- (5,0);
\draw [line width=1pt] (5,0)-- (5,5);
\draw [line width=1pt] (5,5)-- (0,5);
\draw [line width=1pt] (0,5)-- (0,0);
\draw [fill=black] (0,0) circle (1.8pt);
\draw[color=black] (0.05,-0.45) node {$D$};
\draw [fill=black] (5,0) circle (1.8pt);
\draw[color=black] (5.05,-0.45) node {$C$};
\draw [fill=black] (5,5) circle (1.8pt);
\draw[color=black] (5.0,5.4) node {$B$};
\draw [fill=black] (0,5) circle (1.8pt);
\draw[color=black] (0.05,5.4) node {$A$};
\draw[color=black] (2.5,-0.45) node {$e_3$};
\draw[color=black] (5.4,2.7) node {$e_2$};
\draw[color=black] (2.5,5.3) node {$e_1$};
\draw[color=black] (-0.4,2.7) node {$e_4$};
\end{tikzpicture}
\end{document}
答案1
您的圖像可以透過多種不同的方式繪製。一種方法是使用tikz
庫positioning
並quotes
給出相對較短的程式碼:
\documentclass[tikz, margin=3pt]{standalone}
\usetikzlibrary{arrows.meta,
positioning,
quotes}
\begin{document}
\begin{tikzpicture}[
dot/.style = {circle, fill, inner sep=1.6pt, outer sep=0pt,
node contents={}},
every edge/.style = {draw, line width=1pt,-{Stealth[angle=60:3pt 3]}}
]
\node (d) [dot,label=below:$D$];
\node (c) [dot,label=below:$C$, right=5 of d];
\node (b) [dot,label=$B$,above=5.4 of c];
\node (a) [dot,label=$A$,above=5.4 of d];
%
\draw (a) edge ["$e_1$"] (b)
(b) edge ["$e_2$"] (c)
(c) edge ["$e_3$"] (d)
(d) edge ["$e_4$"] (a);
\end{tikzpicture}
\end{document}
上圖中的節點相對於前一個節點定位,頂點標籤被寫入定義它們的節點的標籤,因為邊緣標籤使用庫quotes
。透過定義連接頂點的 eh 邊來加入箭頭
編輯:
ups,我忘記了箭頭......現在添加了。
答案2
這是一種方法。
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[thick,>=stealth,
n/.style={circle,fill,minimum size=2mm,inner sep=0}]
\def\a{5}
\path
(0,0) node[n] (A) {} node[above left] {A}
++(0:\a) node[n] (B) {} node[above right] {B}
++(-90:\a) node[n] (C) {} node[below right] {C}
++(180:\a) node[n] (D) {} node[below left] {D};
\draw[->] (A)--(B) node[midway,above] {$e_1$};
\draw[->] (B)--(C) node[midway,right] {$e_2$};
\draw[->] (C)--(D) node[midway,below] {$e_3$};
\draw[->] (D)--(A) node[midway,left] {$e_4$};
\end{tikzpicture}
\end{document}