我想把我的树排列成 2 x 2 的形状。但是我得到的却是这样的:
我做错了什么?我没有发现我的错误。
\documentclass[a4paper,11pt]{article}
\usepackage{tikz}
\usepackage{subfigure}
\usepackage{array}
\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}
\usepackage{forest}
\begin{document}
\begin{figure}[htbp]
\begin{tabular}{C{.48\textwidth}C{.48\textwidth}}
\subfigure [Subfigure 1] {
\resizebox{0.4\textwidth}{!}{%
\begin{forest}
for tree={delay={where content={}{content={\phantom{00}}}{}},s sep+=5mm,l+=5mm}
[,circle,fill=black,inner sep=1mm
[,circle,fill=red,inner sep=0.5mm
[,circle,draw,red,inner sep=0.25mm,edge={red}
[,circle,draw,red,inner sep=0.25mm,edge={red}]
]
[,circle,draw,red,inner sep=0.5mm
[,circle,draw,red,inner sep=0.25mm,edge={red}]
]
]
[,circle,fill=blue,inner sep=0.5mm
[,circle,draw,blue,inner sep=0.25mm,edge={blue}
]
]
[,circle,fill=green,inner sep=0.5mm]
[,circle,fill=orange,inner sep=0.5mm
]
]
\end{forest}
}}&
\subfigure [Subfigure 2] {
\resizebox{0.4\textwidth}{!}{%
\begin{forest}
for tree={delay={where content={}{content={\phantom{00}}}{}},s sep+=5mm,l+=5mm}
[,circle,fill=black,inner sep=1mm
[,circle,fill=red,inner sep=0.5mm
[,circle,draw,red,inner sep=0.25mm,edge={red}]
[,circle,draw,red,inner sep=0.5mm
]
]
[,circle,fill=blue,inner sep=0.5mm
[,circle,draw,blue,inner sep=0.25mm,edge={blue}
[,circle,draw,blue,inner sep=0.25mm,edge={blue}]
]
[,circle,draw,blue,inner sep=0.25mm,edge={blue}
]
]
[,circle,fill=green,inner sep=0.5mm
]
[,circle,fill=orange,inner sep=0.5mm
]
]
\end{forest}
}}\
\subfigure [Subfigure 3]{
\resizebox{0.4\textwidth}{!}{%
\begin{forest}
for tree={delay={where content={}{content={\phantom{00}}}{}},s sep+=5mm,l+=5mm}
[,circle,fill=black,inner sep=1mm
[,circle,fill=red,inner sep=0.5mm]
[,circle,fill=blue,inner sep=0.5mm]
[,circle,fill=green,inner sep=0.5mm
[,circle,draw,green,inner sep=0.25mm,edge={green}]
]
[,circle,fill=orange,inner sep=0.5mm
[,circle,draw,orange,inner sep=0.25mm,edge={orange}]
[,circle,draw,orange,inner sep=0.25mm,edge={orange}
[,circle,draw,orange,inner sep=0.25mm,edge={orange}]
]
]
]
\end{forest}
}}
\subfigure [Subfigure 4] {
\resizebox{0.4\textwidth}{!}{%
\begin{forest}
for tree={delay={where content={}{content={\phantom{00}}}{}},s sep+=5mm,l+=5mm}
[,circle,fill=black,inner sep=1mm
[,circle,fill=red,inner sep=0.5mm]
[,circle,fill=blue,inner sep=0.5mm]
[,circle,fill=green,inner sep=0.5mm
[,circle,draw,green,inner sep=0.25mm,edge={green}]
[,circle,draw,green,inner sep=0.25mm,edge={green}]
]
[,circle,fill=orange,inner sep=0.5mm
[,circle,draw,orange,inner sep=0.25mm,edge={orange}]
[,circle,draw,orange,inner sep=0.25mm,edge={orange}]
[,circle,draw,orange,inner sep=0.25mm,edge={orange}
[,circle,draw,orange,inner sep=0.25mm,edge={orange}
[,circle,draw,orange,inner sep=0.25mm,edge={orange}]
]
]
]
]
\end{forest}
}}
\end{tabular}
\end{figure}
\end{document}
答案1
在您的代码中,缺少双反斜杠\\
和第二个反斜杠&
。(请参见下面代码中标记的位置。)
\documentclass[a4paper,11pt]{article}
\usepackage{tikz}
\usepackage{subfigure}
\usepackage{array}
\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}
\usepackage{forest}
\begin{document}
\begin{figure}[htbp]
\begin{tabular}{C{.48\textwidth}C{.48\textwidth}}
\subfigure [Subfigure 1] {
\resizebox{0.4\textwidth}{!}{%
\begin{forest}
for tree={delay={where content={}{content={\phantom{00}}}{}},s sep+=5mm,l+=5mm}
[,circle,fill=black,inner sep=1mm
[,circle,fill=red,inner sep=0.5mm
[,circle,draw,red,inner sep=0.25mm,edge={red}
[,circle,draw,red,inner sep=0.25mm,edge={red}]
]
[,circle,draw,red,inner sep=0.5mm
[,circle,draw,red,inner sep=0.25mm,edge={red}]
]
]
[,circle,fill=blue,inner sep=0.5mm
[,circle,draw,blue,inner sep=0.25mm,edge={blue}
]
]
[,circle,fill=green,inner sep=0.5mm]
[,circle,fill=orange,inner sep=0.5mm
]
]
\end{forest}
}}&
\subfigure [Subfigure 2] {
\resizebox{0.4\textwidth}{!}{%
\begin{forest}
for tree={delay={where content={}{content={\phantom{00}}}{}},s sep+=5mm,l+=5mm}
[,circle,fill=black,inner sep=1mm
[,circle,fill=red,inner sep=0.5mm
[,circle,draw,red,inner sep=0.25mm,edge={red}]
[,circle,draw,red,inner sep=0.5mm
]
]
[,circle,fill=blue,inner sep=0.5mm
[,circle,draw,blue,inner sep=0.25mm,edge={blue}
[,circle,draw,blue,inner sep=0.25mm,edge={blue}]
]
[,circle,draw,blue,inner sep=0.25mm,edge={blue}
]
]
[,circle,fill=green,inner sep=0.5mm
]
[,circle,fill=orange,inner sep=0.5mm
]
]
\end{forest}
}}\\ % <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< HERE HERE HERE
\subfigure [Subfigure 3]{
\resizebox{0.4\textwidth}{!}{%
\begin{forest}
for tree={delay={where content={}{content={\phantom{00}}}{}},s sep+=5mm,l+=5mm}
[,circle,fill=black,inner sep=1mm
[,circle,fill=red,inner sep=0.5mm]
[,circle,fill=blue,inner sep=0.5mm]
[,circle,fill=green,inner sep=0.5mm
[,circle,draw,green,inner sep=0.25mm,edge={green}]
]
[,circle,fill=orange,inner sep=0.5mm
[,circle,draw,orange,inner sep=0.25mm,edge={orange}]
[,circle,draw,orange,inner sep=0.25mm,edge={orange}
[,circle,draw,orange,inner sep=0.25mm,edge={orange}]
]
]
]
\end{forest}
}}& % <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< HERE HERE HERE
\subfigure [Subfigure 4] {
\resizebox{0.4\textwidth}{!}{%
\begin{forest}
for tree={delay={where content={}{content={\phantom{00}}}{}},s sep+=5mm,l+=5mm}
[,circle,fill=black,inner sep=1mm
[,circle,fill=red,inner sep=0.5mm]
[,circle,fill=blue,inner sep=0.5mm]
[,circle,fill=green,inner sep=0.5mm
[,circle,draw,green,inner sep=0.25mm,edge={green}]
[,circle,draw,green,inner sep=0.25mm,edge={green}]
]
[,circle,fill=orange,inner sep=0.5mm
[,circle,draw,orange,inner sep=0.25mm,edge={orange}]
[,circle,draw,orange,inner sep=0.25mm,edge={orange}]
[,circle,draw,orange,inner sep=0.25mm,edge={orange}
[,circle,draw,orange,inner sep=0.25mm,edge={orange}
[,circle,draw,orange,inner sep=0.25mm,edge={orange}]
]
]
]
]
\end{forest}
}}
\end{tabular}
\end{figure}
\end{document}