我想绘制一个三角形,其边缘(角)上有文字,如图所示。
MWE [修改自1] 是:
\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\tikzset{
buffer/.style={
draw,
shape border rotate=90,
isosceles triangle,
isosceles triangle apex angle=60,
node distance=2cm,
minimum height=2em
}
}
\begin{document}
\begin{tikzpicture}
\node[buffer]{Text};
\draw node[above]{Text};
\end{tikzpicture}
\end{document}
答案1
这里有两个解决方案。一个是将文本节点放置在三角形后面,另一个是使用三个标签来放置文本。
\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, positioning}
\tikzset{
buffer/.style={
draw,
shape border rotate=90,
isosceles triangle,
isosceles triangle apex angle=60,
node distance=2cm,
minimum height=2em
},
textblock/.style={text width=2cm, inner sep=0pt, align=#1},
}
\begin{document}
\begin{tikzpicture}
\node[buffer] (a) {Text.in};
\node[textblock=center, above= 1mm of a]{Some text text text text text text};
\node[textblock=left, above right= 0mm and 0mm of a.right corner]{Right text text text text text text text};
\node[textblock=right, above left= 0mm and 0mm of a.left corner]{Left text text text text text text text};
\end{tikzpicture}
\begin{tikzpicture}
\node[buffer, label={[textblock=center]above:Above text text},
label={[textblock=left, anchor=south west]right corner:Right text text},
label={[textblock=right, anchor=south east]left corner:Left text text},
] (a) {Text.in};
\end{tikzpicture}
\end{document}