我的目标是制作一个像示例那样的 Tikz 图片,里面有白色方框和字母。
这是我目前所做的(我的示例有灰色框)。我不确定如何像带有白色框的图片一样均匀地堆叠它。我的 LaTeX 代码在底部...然后我想将图形输出为图像文件,例如 jpeg 或 tif 或 png。
\begin{tikzpicture}[>=latex]
\tikzstyle{rect}=[draw=black,
rectangle,
fill=gray,
fill opacity = 0.2,
text opacity=1,
minimum width=100pt,
minimum height = 50pt,
align=center]
\node[rect] (a1) {A};
\node[rect,below right=of a1] (a3) {C};
\node[rect,above right=of a1] (a2) {B};
\draw[->] (a1.north)--(a2.west)node[midway,sloped, above,xshift=-2mm]{1};
\draw[->] (a1.south)--(a3.west)node[midway,sloped, below,xshift=-2mm]{2};
\draw[->] (a2.south)--(a3.north)node[midway, xshift=6mm]{3};
\end{tikzpicture}
\end{figure}
答案1
这是排列节点的众多方法之一。另请注意,这种方法\tikzstyle
已被弃用。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{figure}
\begin{tikzpicture}[>=latex,rect/.style={draw=black,
rectangle,
fill=gray,
fill opacity = 0.2,
text opacity=1,
minimum width=100pt,
minimum height = 50pt,
align=center}]
\node[rect] (a1) {A};
\node[rect,right=100pt of a1] (a2) {B};
\path (a1) -- (a2) node[midway,below=60pt,rect] (a3) {C};
\draw[->] (a1)--(a2)node[midway,sloped, above]{1};
\draw[->] (a1.south)--(a3.west)node[midway,sloped,below]{2};
\draw[->] (a2.south)--(a3.east)node[midway,sloped,below]{3};
\end{tikzpicture}
\end{figure}
\end{document}
答案2
另一种方法是添加arrows.meta
TikZquotes
库:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
positioning,
quotes}
\begin{document}
\begin{figure}
\begin{tikzpicture}[
node distance= 9mm and 0mm,
rect/.style = {draw=black, fill=gray!20, %font=\LARGE,
minimum width=100pt, minimum height = 50pt},
every edge/.style = {draw, -Latex},
every edge quotes/.style = {sloped, auto=right}
]
\node[rect] (a) {A};
\node[rect,below right=of a] (c) {C};
\node[rect,above right=of c] (b) {B};
%
\path (a) edge["1" swap] (b)
(a.south) edge["2"] (c.west)
(b.south) edge["3"] (c.east);
\end{tikzpicture}
\end{figure}
\end{document}