我正在尝试绘制下图,这是代码
\[\begin{tikzpicture}
]
\draw[ arrow] (0,0)--(8,0);
\draw[arrow] (4,4)--(8,0);
\draw[arrow] (0,0)--(4,4);
\draw [arrow](2,2)--(4,0);
\draw [arrow](6,2)--(4,0);
\draw [arrow](6,2)--(2,2);
\node[left] at (0,0) {$a_{i}$};
\node[right] at (8,0) {$a_j$};
\node[above] at (4,4) {$a_k$};
\node[below] at (4,0) {$a_{ij}$};
\node[above] at (2,2) {$a_{ik}$};
\node[above] at (6,2) {$a_{jk}$};
\end{tikzpicture}\]
我想改变箭头的方向,就像图中蓝色箭头一样。
答案1
像这样:
代码:
\documentclass[10pt,a4paper]{article}
\usepackage{tikz}
\usetikzlibrary{decorations.markings}
\begin{document}
\begin{tikzpicture}
%\draw[gray!25](0,0) grid(8,4);
\begin{scope}[very thick,decoration={
markings,
mark=at position 0.5 with {\arrow{>}}}
]
\draw[postaction={decorate}] (0,0)--(4,0);
\draw[postaction={decorate}] (4,0)--(8,0);
\draw[postaction={decorate}] (4,0)--(2,2);
\draw[postaction={decorate}] (0,0)--(2,2);
\draw [postaction={decorate}](2,2)--(4,4);
\draw [postaction={decorate}](6,2)--(4,0);
\draw [postaction={decorate}](2,2)--(6,2);
\draw[postaction={decorate}] (6,2)--(4,4);
\draw[postaction={decorate}] (8,0)--(6,2);
\end{scope}
\node[left] at (0,0) {$a_{i}$};
\node[right] at (8,0) {$a_j$};
\node[above] at (4,4) {$a_k$};
\node[below] at (4,0) {$a_{ij}$};
\node[above] at (2,2) {$a_{ik}$};
\node[above] at (6,2) {$a_{jk}$};
\end{tikzpicture}
\end{document}
答案2
两种选择。
- 一个普通的 TikZ 图片,具有两个三角形和一堆边缘节点。
- TikZ-CD 中的节点位于交叉点的位置。
代码
\documentclass[tikz]{standalone}
\usetikzlibrary{cd, arrows.meta, quotes}
\tikzset{
pics/arrow/.style={/tikz/sloped, /tikz/allow upside down,
code=\pgfarrowdraw{#1}}, pics/arrow/.default=>}
\begin{document}
\tikz[
>=Straight Barb, line join=round, thick,
execute at begin node=$, execute at end node=$,
ar2/.style={edge node={pic[near start]{arrow}pic[near end]{arrow}}},
ar2'/.style={edge node={pic[near start]{arrow=<}pic[near end]{arrow=<}}},
ar/.style={edge node={pic{arrow}}},
auto=right, mc/.style={edge node={coordinate(#1)}},
]
\draw (0,0) node[left]{a_i} to["a_{ij}", ar2, mc=a] +(right:8) node[right]{a_j}
to["a_{jk}", ar2, mc=b] +(4,6) node[above]{a_k}
to["a_{ik}", ar2',mc=c] cycle
(a) to[ar] (c) to[ar] (b) to[ar] cycle;
\begin{tikzcd}[
row sep=huge,
arrows={thick, dash,
/tikz/every to/.append style={edge node={pic {arrow=Straight Barb}}}}]
& & a_k \\
& a_{ik} \urar\ar[rr] & & a_{jk} \dlar\ular \\
a_i \urar\ar[rr] & & a_{ij} \ular\ar[rr] & & a_j \ular
\end{tikzcd}
\end{document}
输出
答案3
另一个可能的解决方案:
\documentclass[10pt,a4paper]{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
decorations.markings}
\begin{document}
\begin{tikzpicture}[
> = Straight Barb,
every edge/.append style = {very thick,
decoration={markings,
mark=at position 0.5 with {\arrow{>}}},
postaction={decorate}
},
lbl/.style ={label=#1, coordinate, node contents={}}
]
\draw (0,0) node[lbl=left:$a_{i}$] edge (4,0)
(4,0) node[lbl=below:$a_{ij}$] edge (8,0)
(8,0) node[lbl=right:$a_j$] edge (6,2)
(6,2) node[lbl=right:$a_{jk}$] edge (4,4)
(4,4) node[lbl=above:$a_{k}$]
%
(0,0) edge (2,2)
(2,2) node[lbl=left:$a_{ik}$] edge (4,4)
%
(6,2) edge (4,0)
(4,0) edge (2,2)
(2,2) edge (6,2)
;
\end{tikzpicture}
\end{document}