我对 TIKZ 不是很有经验,但我制作了一些这样的图表。
当我尝试将标签名称更改为希腊字母时,我遇到了错误。有没有办法修改我的代码,将标签更改为 alpha、beta 等?
以下是代码:
\documentclass{beamer}
\usepackage{tikz}
\usepackage{verbatim}
\usetikzlibrary{arrows,shapes}
\begin{document}
\pgfdeclarelayer{background}
\pgfsetlayers{background,main}
\tikzstyle{vertex}=[circle,fill=black!25,minimum size=14pt,inner sep=0pt]
\tikzstyle{selected vertex} = [vertex, fill=red!24]
\tikzstyle{edge} = [draw,thick,-]
\tikzstyle{weight} = [font=\small]
\tikzstyle{selected edge} = [draw,line width=5pt,-,red!50]
\tikzstyle{ignored edge} = [draw,line width=5pt,-,black!20]
%Start of graph
\begin{tikzpicture}[scale=.7, auto,swap]
\foreach \pos/\name in {{(0,0)/a},{(2,0)/b},{(3,2)/c},{(2,4)/d},{(0,4)/e},
{(-1,2)/f},{(-1,-1)/1},{(-2,-2)/2},{(3,-1)/3},{(4,-2)/4},{(4,2)/5},
{(5,2)/6},{(-2,2)/7},{(-3,2)/8},{(-1,5)/9},{(-2,6)/10},{(3,5)/11},
{(4,6)/12}}
\node[vertex] (\name) at \pos {$\name$};
% Connect vertices with edges
\foreach \source/ \dest /\weight in {a/b/, b/c/, c/d/, d/e/,
e/f/,f/a/,a/1/,1/2/,b/3/,3/4/,c/5/,5/6/,f/7/,7/8/,e/9/,9/10/,d/11/,11/12/}
\path[edge] (\source) -- node[weight] {$\weight$} (\dest);
\end{tikzpicture}
\end{document}
答案1
您可以将第一个循环一分为二,为第一部分引入第三个循环变量,代表节点文本(\alpha
,,\beta
等等)。
\documentclass{beamer}
\usepackage{tikz}
\usepackage{verbatim}
\usetikzlibrary{arrows,shapes}
\begin{document}
\begin{frame}
\pgfdeclarelayer{background}
\pgfsetlayers{background,main}
\tikzset{
vertex/.style={circle,fill=black!25,minimum size=14pt,inner sep=0pt},
selected vertex/.style={vertex, fill=red!24},
edge/.style={draw,thick,-},
weight/.style={font=\small},
selected edge/.style={draw,line width=5pt,-,red!50},
ignored edge/.style={draw,line width=5pt,-,black!20}
}
%Start of graph
\begin{tikzpicture}[scale=.7, auto,swap]
\foreach \pos/\name/\txt in {{(0,0)/a/\alpha},{(2,0)/b/\beta},{(3,2)/c/\gamma},{(2,4)/d/\delta},{(0,4)/e/\epsilon},{(-1,2)/f/\zeta}}
{
\node[vertex] (\name) at \pos {$\txt$};
}
\foreach \pos/\name in
{{(-1,-1)/1},{(-2,-2)/2},{(3,-1)/3},{(4,-2)/4},{(4,2)/5},
{(5,2)/6},{(-2,2)/7},{(-3,2)/8},{(-1,5)/9},{(-2,6)/10},{(3,5)/11},
{(4,6)/12}}
\node[vertex] (\name) at \pos {$\name$};
% Connect vertices with edges
\foreach \source/ \dest /\weight in {a/b/, b/c/, c/d/, d/e/,
e/f/,f/a/,a/1/,1/2/,b/3/,3/4/,c/5/,5/6/,f/7/,7/8/,e/9/,9/10/,d/11/,11/12/}
\path[edge] (\source) -- node[weight] {$\weight$} (\dest);
\end{tikzpicture}
\end{frame}
\end{document}