
나는 그래프를 그리고 싶다. 나는 사용한다틱즈 매트릭스정점을 그린 다음 배열에서 가장자리를 추가하고 싶습니다. 다음 코드를 시도했습니다.
\documentclass{article}
\usepackage{tikz,pgfmath}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}
\matrix (w) [nodes={circle,draw,scale=0.66}, matrix of nodes, row sep=2em, column sep=0.5em]{
1&2&3\\
&4&5\\
&6\\
};
\def\V{{"w-1-1","w-1-2","w-1-3","w-2-2","w-2-3","w-3-2"}}
%\draw[->] (\V[1]) to (\V[2]); %Line A
%\node at (1,1) {\pgfmathparse{\V[2]}\pgfmathresult}; %Line B
\draw[->] (\pgfmathparse{\V[1]}\pgfmathresult) to (\pgfmathparse{\V[2]}\pgfmathresult); %Line C
\end{tikzpicture}
\end{document}
나는 노력했다라인 A먼저, 작동하지 않았습니다. 배열에 올바르게 액세스하려면 다음을 사용해야 한다는 것이 밝혀졌습니다.pdfmathparse. 그러나 코드는 컴파일되지 않습니다(비록B선잘 작동합니다). (출력된 것 같습니다.pgfmath결과문자열이 아닌 문자열입니다.그리다기대한다.)
추신: 원래 동기는 그래프 페블링을 간결하게 설명하는 것이었습니다. 어쨌든 결과와 함께 최종 코드를 첨부했습니다.
\documentclass{article}
\usepackage{tikz,pgfmath,xstring,algorithm}
\usetikzlibrary{matrix}
\newcommand{\Configuration}[6]{%A fixed graph
\begin{minipage}{.2\textwidth}%1
\begin{tikzpicture}
\matrix (w) [nodes={circle,draw,scale=0.6}, matrix of nodes, row sep=2em, column sep=0.5em,ampersand replacement=\&]{
1\&2\&3\\
\&4\&5\\
\&6\\
};
\def\V{{"w-1-1","w-1-2","w-1-3","w-2-2","w-2-3","w-3-2"}}%the mapping
\foreach \x/\y/\z in {{1/4/#1},{2/4/#2},{3/4/#3},{3/5/#4},{4/6/#5},{5/6/#6}}%pebbling
\pgfmathsetmacro{\X}{\V[\x-1]}
\pgfmathsetmacro{\Y}{\V[\y-1]}
\draw[->] (\X) to node {\ifthenelse{\z=0}{}{$\bullet$}} (\Y);
\end{tikzpicture}
\end{minipage}
}
\begin{document}
\begin{figure}
\centering
\Configuration{0}{0}{0}{0}{0}{0}
\Configuration{1}{0}{0}{0}{0}{0}
\Configuration{1}{1}{0}{0}{0}{0}
\Configuration{1}{1}{1}{0}{0}{0}
\Configuration{1}{1}{1}{0}{1}{0}
\Configuration{1}{1}{0}{0}{1}{0}
\Configuration{1}{0}{0}{0}{1}{0}
\Configuration{0}{0}{0}{0}{1}{0}
\Configuration{0}{0}{0}{1}{1}{0}
\Configuration{0}{0}{0}{1}{1}{1}
\Configuration{0}{0}{0}{0}{1}{1}
\end{figure}
\end{document}
답변1
\pgfmathsetmacro
당신이 원하는 것이 무엇인지 확실하지 않지만 이것이 문제를 해결한다고 생각합니다 .
\documentclass [border=2mm]{standalone}
\usepackage{tikz}
\usepackage{tikz,pgfmath}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}
\matrix (w) [nodes={circle,draw,scale=0.66}, matrix of nodes, row sep=2em, column sep=0.5em]{
1&2&3\\
&4&5\\
&6\\
};
\def\V{{"w-1-1","w-1-2","w-1-3","w-2-2","w-2-3","w-3-2"}}
\pgfmathsetmacro{\start}{\V[1]}
\pgfmathsetmacro{\finish}{\V[2]}
\draw[->] (\start) to (\finish); %Line C
\end{tikzpicture}
\end{document}