答案1
如果这对您来说是一个选项,您可以使用箭头作为节点来解决它:
由于这个答案包含一个错误(嵌套 tikz 环境)并且有一个后续问题,你可以找到一个改进的版本这里。
\documentclass[border=0.5cm]{standalone}
\usepackage{tikz}
\newcommand{\arrowL}{
\tikz \draw[latex-] (0,0) -- (0.1,0);
}
\newcommand{\arrowR}{
\tikz \draw[-latex] (0,0) -- (0.1,0);
}
\begin{document}
\begin{tikzpicture}
% Triangle 1
\node at (2,-1) {triangle 1};
\draw (0,0)--(4,0) node[sloped,pos=0.5]{};
\draw (4,0)--(4,4) node[sloped,pos=0.5]{\arrowR};
\draw (0,0)--(4,4) node[sloped,pos=0.5]{\arrowL};
\end{tikzpicture}
\begin{tikzpicture}
%Triangle 2
\node at (2,-1) {triangle 2};
\draw (0,0)--(4,0) node[sloped,pos=0.5]{};
\draw (4,0)--(4,4) node[sloped,pos=0.5]{\arrowR};
\draw (0,0)--(4,4) node[sloped,pos=0.5]{\arrowR};
\end{tikzpicture}
\begin{tikzpicture}
%Triangle 3
\node at (2,-1) {triangle 2};
\draw (0,0)--(0,4) node[sloped,pos=0.5]{\arrowR};
\draw (0,4)--(4,0) node[sloped,pos=0.5]{\arrowL};
\draw (0,0)--(4,0) node[sloped,pos=0.5]{};
\end{tikzpicture}
\begin{tikzpicture}
%arrows 1
\node at (2,-1) {horizontal};
\draw (0,0)--(4,0) node[sloped,pos=0.5]{\arrowL}; % makes an arrow pointing from the first coordinate to the last one to the left
\draw (0,1)--(4,1) node[sloped,pos=0.5]{\arrowR}; % makes an arrow pointing from the first coordinate to the last one to the right.
\end{tikzpicture}
\begin{tikzpicture}
%arrows 2
\node at (2,-1) {vertical};
\draw (1,0)--(1,4) node[sloped,pos=0.5]{\arrowL}; % makes an arrow pointing from the first coordinate to the last one down
\draw (2,0)--(2,4) node[sloped,pos=0.5]{\arrowR}; % makes an arrow pointing from the first coordinate to the last one up
\end{tikzpicture}
\end{document}