编辑

编辑

我有以下代码:

\documentclass[10pt]{article}
\usepackage{fullpage,amsmath,amssymb,amsfonts,nicefrac, amsthm,calc}
\usepackage{caption}
\usepackage{listings}
\usepackage{qtree}

\begin{document}
\pagenumbering{gobble}

\newpage
\begin{enumerate}
\item 
{\centering
\begin{tabular}{|c|c|c|c|c|c|c|c|c|c|c|}
\hline
$8$ & $11$ & $9$ & $6$ & $7$ & $2$ & $4$ & $5$ & $10$ & $1$ & $3$ \\
\hline
\end{tabular}

\Tree[.8 [.11 [.6 [.5 ] [.10 ]] [.7 [.1 ] [.3 ]]]
               [.9   [.2 ] [.4 ]]]
}

\medskip
\medskip
\medskip
\medskip
\medskip

{\centering
\begin{tabular}{|c|c|c|c|c|c|c|c|c|c|c|}
\hline
$8$ & $11$ & $9$ & $6$ & $1$ & $2$ & $4$ & $5$ & $10$ & $7$ & $3$ \\
\hline
\end{tabular}

\Tree[.8 [.11 [.6 [.5 ] [.10 ]] [.1 [.7 ] [.3 ]]]
               [.9   [.2 ] [.4 ]]]
}

\medskip
\medskip
\medskip
\medskip
\medskip

{\centering
\begin{tabular}{|c|c|c|c|c|c|c|c|c|c|c|}
\hline
$8$ & $11$ & $9$ & $5$ & $1$ & $2$ & $4$ & $6$ & $10$ & $7$ & $3$ \\
\hline
\end{tabular}

\Tree[.8 [.11 [.5 [.6 ] [.10 ]] [.1 [.7 ] [.3 ]]]
               [.9   [.2 ] [.4 ]]]
}

\medskip
\medskip
\medskip
\medskip
\medskip

{\centering
\begin{tabular}{|c|c|c|c|c|c|c|c|c|c|c|}
\hline
$8$ & $11$ & $2$ & $5$ & $1$ & $9$ & $4$ & $6$ & $10$ & $7$ & $3$ \\
\hline
\end{tabular}

\Tree[.8 [.11 [.5 [.6 ] [.10 ]] [.1 [.7 ] [.3 ]]]
               [.2   [.9 ] [.4 ]]]
}

\medskip
\medskip
\medskip
\medskip
\medskip

{\centering
\begin{tabular}{|c|c|c|c|c|c|c|c|c|c|c|}
\hline
$8$ & $1$ & $2$ & $5$ & $3$ & $9$ & $4$ & $6$ & $10$ & $7$ & $11$ \\
\hline
\end{tabular}

\Tree[.8 [.1 [.5 [.6 ] [.10 ]] [.3 [.7 ] [.11 ]]]
               [.2   [.9 ] [.4 ]]]
}

\medskip
\medskip
\medskip
\medskip
\medskip

{\centering
\begin{tabular}{|c|c|c|c|c|c|c|c|c|c|c|}
\hline
$1$ & $3$ & $2$ & $5$ & $7$ & $9$ & $4$ & $6$ & $10$ & $8$ & $11$ \\
\hline
\end{tabular}

\Tree[.1 [.3 [.5 [.6 ] [.10 ]] [.7 [.8 ] [.11 ]]]
               [.2   [.9 ] [.4 ]]]
}

\end{enumerate}
\end{document}

我觉得树木占用了太多空间,所以我想让它们每行两列,而不是每行一列。如果我能以某种方式给它们编号,或者能够以其他方式明确指示顺序,那就太好了。我该怎么做?谢谢!

答案1

你想要这样的东西吗?

股票行情树

这使用了一个新命令\ticker{<numbers for ticker tape>}{<code for tree>}。(我使用它只是\ticker因为它对我来说看起来像纸带。)

\documentclass{article}
\usepackage{geometry}
\usepackage{tikz}
\usepackage{qtree}
\pagestyle{empty}
\begin{document}
\newcounter{tapes}
\newcommand*\ticker[2]{%
  \refstepcounter{tapes}%
  \noindent\thetapes.
  \begin{minipage}[t]{.45\textwidth}
    \centering
    \tikz{%
      \coordinate (n0) at (0,0);
      \foreach \i [count=\j, remember=\j as \k (initially 0)] in {#1} \node (n\j) [anchor=south west, draw, text width=12.5pt, text centered, inner ysep=2.5pt, inner xsep=2.5pt, xshift=-\pgflinewidth] at (n\k.south east)  {\i};
    }\par
    #2\medskip\par
  \end{minipage}%
}
\ticker{8,11,9,6,7,2,4,5,10,1,3}{%
  \Tree[.8 [.11 [.6 [.5 ] [.10 ]] [.7 [.1 ] [.3 ]]]
  [.9   [.2 ] [.4 ]]]}\hfill
\ticker{8,11,9,6,1,2,4,5,10,7,3}{%
  \Tree[.8 [.11 [.6 [.5 ] [.10 ]] [.1 [.7 ] [.3 ]]]
  [.9   [.2 ] [.4 ]]]}

\ticker{8,11,9,5,1,2,4,6,10,7,3}{%
  \Tree[.8 [.11 [.5 [.6 ] [.10 ]] [.1 [.7 ] [.3 ]]]
  [.9   [.2 ] [.4 ]]]}\hfill
\ticker{8,11,2,5,1,9,4,6,10,7,3}{%
  \Tree[.8 [.11 [.5 [.6 ] [.10 ]] [.1 [.7 ] [.3 ]]]
  [.2   [.9 ] [.4 ]]]}

\ticker{8,1,2,5,3,9,4,6,10,7,11}{%
  \Tree[.8 [.1 [.5 [.6 ] [.10 ]] [.3 [.7 ] [.11 ]]]
  [.2   [.9 ] [.4 ]]]}\hfill
\ticker{1,3,2,5,7,9,4,6,10,8,11}{%
  \Tree[.1 [.3 [.5 [.6 ] [.10 ]] [.7 [.8 ] [.11 ]]]
  [.2   [.9 ] [.4 ]]]}
\end{document}

编辑

这回答了评论中提出的另一个问题,即如何根据树木的根部将树木置于中心,而不是将树木本身置于中心。

我认为这很难做到,qtree除非你把行情纸带的制作过程破解到\Tree宏中。我已经很久没用过了qtree,但我记得破解它并不是特别有趣。(也就是说,很难让它做它本来不应该做的事情!)

您可以使用 来阻止树木居中qtree,但这并不是我们真正想要的。

为了使根相对于行情纸带居中,我建议放弃qtree并转向更灵活的 Ti基于 Z 的树形绘制包。tikz-qtree是一个选项;forest是另一个选项。我偏爱后者,这并不奇怪。

这是一个 Forest 解决方案。tickertree是一个采用一个强制参数的环境。此参数应指定行情纸带的数字。环境主体应以 Forest 的括号语法给出树规范。

然后

\begin{tickertree}{8,11,9,6,7,2,4,5,10,1,3}
  [8
    [11
      [6
        [5]
        [10]
      ]
      [7
      [1]
      [3]
      ]
    ]
    [9
      [2]
      [4]
    ]
  ]
\end{tickertree}\hfill
\begin{tickertree}{8,11,9,6,1,2,4,5,10,7,3}
  [8[11[6[5][10]][1[7][3]]][9[2][4]]]
\end{tickertree}

\begin{tickertree}{8,11,9,5,1,2,4,6,10,7,3}
  [8[11[5[6][10]][1[7][3]]][9[2][4]]]
\end{tickertree}\hfill
\begin{tickertree}{8,11,2,5,1,9,4,6,10,7,3}
  [8[11[5[6][10]][1[7][3]]][2[9][4]]]
\end{tickertree}

\begin{tickertree}{8,1,2,5,3,9,4,6,10,7,11}
  [8[1[5[6][10]][3[7][11]]][2[9][4]]]
\end{tickertree}\hfill
\begin{tickertree}{1,3,2,5,7,9,4,6,10,8,11}
  [1[3[5[6][10]][7[8][11]]][2[9][4]]]
\end{tickertree}

将产生如上所示的 6 棵带有行情机的树,其根部位于各自磁带的中点以下。

纸带树的森林解决方案

\documentclass{article}
\usepackage{geometry}
\usepackage[linguistics]{forest}
\pagestyle{empty}
\makeatletter
\environbodyname\tickertreebody
\bracketset{action character=@}
\newsavebox\tickertreetape
\newcounter{tapes}
\NewEnviron{tickertree}[1]{%
  \sbox\tickertreetape{%
    \tikz{%
      \coordinate (n0) at (0,0);
      \foreach \i [count=\j, remember=\j as \k (initially 0)] in {#1} \node (n\j) [anchor=south west, draw, text width=12.5pt, text centered, inner ysep=2.5pt, inner xsep=2.5pt, xshift=-\pgflinewidth] at (n\k.south east)  {\i};
    }%
  }%
  \refstepcounter{tapes}%
  \noindent\thetapes.
  \begin{forest}
    before drawing tree={
      !r1.no edge
    },
    before computing xy={
      !r1.l'=\baselineskip,
    }
    [\usebox{\tickertreetape} @\tickertreebody]
  \end{forest}}
\makeatother
\begin{document}

\begin{tickertree}{8,11,9,6,7,2,4,5,10,1,3}
  [8
    [11
      [6
        [5]
        [10]
      ]
      [7
      [1]
      [3]
      ]
    ]
    [9
      [2]
      [4]
    ]
  ]
\end{tickertree}\hfill
\begin{tickertree}{8,11,9,6,1,2,4,5,10,7,3}
  [8[11[6[5][10]][1[7][3]]][9[2][4]]]
\end{tickertree}

\begin{tickertree}{8,11,9,5,1,2,4,6,10,7,3}
  [8[11[5[6][10]][1[7][3]]][9[2][4]]]
\end{tickertree}\hfill
\begin{tickertree}{8,11,2,5,1,9,4,6,10,7,3}
  [8[11[5[6][10]][1[7][3]]][2[9][4]]]
\end{tickertree}

\begin{tickertree}{8,1,2,5,3,9,4,6,10,7,11}
  [8[1[5[6][10]][3[7][11]]][2[9][4]]]
\end{tickertree}\hfill
\begin{tickertree}{1,3,2,5,7,9,4,6,10,8,11}
  [1[3[5[6][10]][7[8][11]]][2[9][4]]]
\end{tickertree}

\end{document}

相关内容