我想制作这个 tikz 图片但发现问题使这些节点填充黑色,中间的虚线并且还想缩小箭头上的数字的大小。
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{hyperref}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,positioning}
%usepackage{algorithm}
\usepackage{pifont}
\title{test}
\author{xyz}
\date{June 2022}
\begin{document}
\maketitle
\section{Introduction}
\begin{figure}[h]
\centering
\begin{tikzpicture}[mycircle/.style={circle,draw=black, text opacity=1, inner sep=5pt}, myarrow/.style={-Stealth, font=\smaller},node distance=0.6cm and 1.2cm]
\node[mycircle] (c1) {$s$};
\node[mycircle,below right=of c1] (c2) {$v_2$};
\node[mycircle,right=of c2] (c3) {$v_4$};
\node[mycircle,above right=of c1] (c4) {$v_1$};
\node[mycircle,right=of c4] (c5) {$v_3$};
\node[mycircle,below right=of c5] (c6) {$t$};
\foreach \i/\j/\txt/\p in {% start node/end node/text/position
c1/c2/7:\textcolor{blue}{4}/below,
c1/c4/8:\textcolor{blue}{5}/above,
c2/c3/6:\textcolor{blue}{5}/below,
c3/c6/2:\textcolor{blue}{2}/below,
c4/c5/6:\textcolor{blue}{6}/above,
c5/c6/10:\textcolor{blue}{7}/above,
c5/c2/9:\textcolor{blue}{2}/below,
c3/c5/5:\textcolor{blue}{3}/below,
c2.70/c4.290/2:\textcolor{blue}{1}/below}
\draw [myarrow] (\i) -- node[sloped,font=\small,\p] {\txt} (\j);
\end{tikzpicture}
\caption{A cut $(S,T)$ in flow network, where $S=(s,v_1.v_2)$ and $T (v_3,v_4,t)$ with net flow across $(S,T)$ is $f(S,T)=9$ and thecapacity $c(S,T)=12$.}
\end{figure}
\end{document}
注意:代码中的数字根据我的要求进行了更改。
答案1
这是使用当前代码的一种方式。手动设置的位置可以通过 中的一些低级函数计算tikz
。可能仍需要进行一些细微的微调,例如使用 中的 Stealth 提示\graph
。
\documentclass[10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{graphs, positioning, arrows.meta}
\begin{document}
\begin{tikzpicture}
[mycircle/.style={circle,draw=black,
text opacity=1, inner sep=5pt},
myarrow/.style={-Stealth, font=\tiny},% <<< or \small
node distance=0.6cm and 1.2cm,
blk/.style={fill=black, text=white}]% <<< black & white
\node[mycircle, blk] (c1) {$s$};
\node[mycircle,below right=of c1, blk] (c2) {$v_2$};
\node[mycircle,right=of c2] (c3) {$v_4$};
\node[mycircle,above right=of c1, blk] (c4) {$v_1$};
\node[mycircle,right=of c4] (c5) {$v_3$};
\node[mycircle,below right=of c5] (c6) {$t$};
\foreach \i/\j/\txt/\p in {% start node/end node/text/position
c1/c2/7:\textcolor{blue}{4}/below,
c1/c4/8:\textcolor{blue}{5}/above,
c2/c3/6:\textcolor{blue}{5}/below,
c3/c6/2:\textcolor{blue}{2}/below,
c4/c5/6:\textcolor{blue}{6}/above,
c5/c6/10:\textcolor{blue}{7}/above,
c5/c2/9:\textcolor{blue}{2}/below,
c3/c5/5:\textcolor{blue}{3}/below,
c2.70/c4.290/2:\textcolor{blue}{1}/below}
\draw [myarrow] (\i) -- node[sloped,\p] {\txt} (\j);
% ~~~ new: introducing some dummy-nodes ~~~~
\node (dum1) [below] at (2.82,-2.1) {S T};% can be calculated
\node (dum2) [below] at (2.82, 2) {};
\node (dum3) [below=of c3] {};
\node (dum4) [below=of c2] {};
\draw [dashed] (dum1.south) -- (dum2);% <<< dashed vertical
\graph{% arrows
(dum1) -> {(dum3), (dum4)};
};
\end{tikzpicture}
\end{document}