这是我的代码,由 pdflatex 编译。
\documentclass[11pt]{article}
\usepackage[a5paper,margin=5pt]{geometry}
\usepackage{amsmath,amssymb}
\usepackage{tikz-qtree}
\begin{document}
\begin{center}
\begin{tikzpicture}[scale=.6]\Tree
[.(0,0)
[.(0,1)
[.(1,1)
[.(1,2)\\$\downarrow$\\(2,0)
[.(3,0)
[.(4,0)\\$\downarrow$\\\textcolor{olive}{(1,3)} ]
[.\textcolor{olive}{(3,1)} ]
]
[.\textcolor{cyan}{(2,1)} ]
]
[.\textcolor{cyan}{(2,1)} ]
]
[.(0,2)
[.(0,3)
[.(1,3)\\$\downarrow$\\\textcolor{purple}{(4,0)} ]
[.\textcolor{purple}{(0,4)} ]
]
[.(1,2)\\$\downarrow$\\(2,0)
[.(3,0)
[.(4,0)\\$\downarrow$\\\textcolor{olive}{(1,3)} ]
[.\textcolor{olive}{(3,1)} ]
]
[.\textcolor{cyan}{(2,1)} ]
]
]
]
[.(1,0)
[.(2,0)\\$\downarrow$\\(1,2)
[.(1,3)\\$\downarrow$\\\textcolor{purple}{(4,0)} ]
[.\textcolor{blue}{(2,2)} ]
]
[.(1,1)
[.(1,2)\\$\downarrow$\\(2,0)
[.(3,0)
[.(4,0)\\$\downarrow$\\\textcolor{olive}{(1,3)} ]
[.\textcolor{olive}{(3,1)} ]
]
[.\textcolor{cyan}{(2,1)} ]
]
[.\textcolor{cyan}{(2,1)} ]
]
]
]
\end{tikzpicture}
\end{center}
\end{document}
根据tikz-qtree
包的文档,可以在节点中使用\\
换行符。但上面的代码无法正确编译。如果我更改包含它的部分,\\
它就会起作用。
为什么会这样?如何在节点中断线?
答案1
看起来你还没有添加
\tikzset{every tree node/.style={align=center,anchor=north}}
后
\begin{tikzpicture}[scale=.6]
在调用之前\Tree
。另外,以防万一,请检查\pgfversion
其是否 > 2.1,如文档所述
\documentclass[11pt]{article}
\usepackage[a5paper,margin=5pt]{geometry}
\usepackage{amsmath,amssymb}
\usepackage{tikz-qtree}
\begin{document}
\begin{center}
\begin{tikzpicture}[scale=.6]
\tikzset{every tree node/.style={align=center,anchor=north}}
\Tree
[.(0,0)
[.(0,1)
[.(1,1)
[.(1,2)\\$\downarrow$\\(2,0)
[.(3,0)
[.(4,0)\\$\downarrow$\\\textcolor{olive}{(1,3)} ]
[.\textcolor{olive}{(3,1)} ]
]
[.\textcolor{cyan}{(2,1)} ]
]
[.\textcolor{cyan}{(2,1)} ]
]
[.(0,2)
[.(0,3)
[.(1,3)\\$\downarrow$\\\textcolor{purple}{(4,0)} ]
[.\textcolor{purple}{(0,4)} ]
]
[.(1,2)\\$\downarrow$\\(2,0)
[.(3,0)
[.(4,0)\\$\downarrow$\\\textcolor{olive}{(1,3)} ]
[.\textcolor{olive}{(3,1)} ]
]
[.\textcolor{cyan}{(2,1)} ]
]
]
]
[.(1,0)
[.(2,0)\\$\downarrow$\\(1,2)
[.(1,3)\\$\downarrow$\\\textcolor{purple}{(4,0)} ]
[.\textcolor{blue}{(2,2)} ]
]
[.(1,1)
[.(1,2)\\$\downarrow$\\(2,0)
[.(3,0)
[.(4,0)\\$\downarrow$\\\textcolor{olive}{(1,3)} ]
[.\textcolor{olive}{(3,1)} ]
]
[.\textcolor{cyan}{(2,1)} ]
]
[.\textcolor{cyan}{(2,1)} ]
]
]
]
\end{tikzpicture}
\end{center}
\end{document}