这个问题在 LaTeX 中绘制图表。
\documentclass[12pt,border=5pt]{standalone}
\usepackage{newcent,pstricks,amsmath,amssymb,pst-arrow}
\usepackage{auto-pst-pdf}
\makeatletter
\newcommand\NCline[2]{\ncline{#1}{#2}\@ifnextchar\bgroup\NCline{}} %% :-))))
\makeatother
\begin{document}
\begin{pspicture}
\begin{psmatrix}[colsep=12mm,rowsep=10mm]
& [name=A1] $000$ & & [name=A2] $111$ & & \\
& & [name=A3] $111$ & & [name=A4] $110$ & \\
& [name=A5] $011$ & & [name=A6] $110$ & & [name=A7] $100$ \\
[name=A8] $001$ & & [name=A9] $101$ & & [name=A10] $110$ &
\end{psmatrix}
\psset{nodesep=5pt , arrows=->, arrowsize=5pt, arrowlength=1}
\ncline{A1}{A3}{A3}{A2}{A2}{A4}
\ncline{A5}{A3}{A3}{A6}{A6}{A4}{A4}{A7}
\ncline{A8}{A5}{A5}{A9}{A9}{A6}{A6}{A10}{A10}{A7}
\end{pspicture}
\end{document}
编译结果:
问题:
我遇到了错误。如何解决?如果你有更短的方法,你可以改进它。
答案1
\foreach \i/\j in {1/3,3/2,2/4,5/3,3/6,6/4,4/7,8/5,5/9,9/6,6/10,10/7}{\ncline{A\i}{A\j}}
更优雅,不是吗?
\documentclass[preview,12pt,border=5pt]{standalone}
\usepackage{pst-node}
\begin{document}
\begin{psmatrix}[colsep=12mm,rowsep=10mm]
& [name=A1] $000$ & & [name=A2] $111$ & & \\
& & [name=A3] $111$ & & [name=A4] $110$ & \\
& [name=A5] $011$ & & [name=A6] $110$ & & [name=A7] $100$ \\
[name=A8] $001$ & & [name=A9] $101$ & & [name=A10] $110$
\end{psmatrix}
\psset{nodesep=5pt,arrows=->,arrowsize=5pt,arrowlength=1}
\foreach \i/\j in {1/3,3/2,2/4,5/3,3/6,6/4,4/7,8/5,5/9,9/6,6/10,10/7}{\ncline{A\i}{A\j}}
\end{document}
答案2
\documentclass[12pt,border=5pt]{standalone}
\usepackage{pst-node}
\usepackage{auto-pst-pdf}
\makeatletter
\let\NCline\ncline
\def\ncline#1#2{\NCline{#1}{#2}\@ifnextchar\bgroup{\ncline}{}}
\makeatother
\begin{document}
\begin{pspicture}(5,5)
\begin{psmatrix}[colsep=12mm,rowsep=10mm]
& [name=A1] $000$ & & [name=A2] $111$ & & \\
& & [name=A3] $111$ & & [name=A4] $110$ & \\
& [name=A5] $011$ & & [name=A6] $110$ & & [name=A7] $100$ \\
[name=A8] $001$ & & [name=A9] $101$ & & [name=A10] $110$ &
\end{psmatrix}
\psset{nodesep=5pt , arrows=->, arrowsize=5pt, arrowlength=1}
\ncline{A1}{A3}{A3}{A2}{A2}{A4}
\ncline{A5}{A3}{A3}{A6}{A6}{A4}{A4}{A7}
\ncline{A8}{A5}{A5}{A9}{A9}{A6}{A6}{A10}{A10}{A7}
\end{pspicture}
\end{document}