带有括号的表格连接元素

带有括号的表格连接元素

我想制作一棵带有支架的垂直树,就像下面这样。

在此处输入图片描述

我试过,\overbrace但无法将第二行节点(\Omega_{r}\Omega_{m})与第一行节点连接起来。

\begin{tabular}{l|c c c}
Total matter&& $\Omega$ &\\
Different equations of state &$\Omega_{m}$&$\Omega_{r}$&$\Omega_{\Lambda}$\\
Difefrent species &$\overbrace{\Omega_{b}\quad\Omega_{c}}^{}$&
 $\overbrace{\Omega_{\gamma}\quad\Omega_{\nu}}^{}$&
\end{tabular}

我明白了

在此处输入图片描述

答案1

一个解决方案\raisebox(通过反复试验!):

\documentclass{article}
\usepackage{mathtools}

\begin{document}

\begin{tabular}{l|c c c}
Total matter & \multicolumn{3}{c}{\enspace\raisebox{-3.3ex}[0pt][2.6ex]{$ \overbrace{\vphantom{-}\hspace{9.5em}}^{\textstyle \Omega}$}}\\
Different equations of state & $\Omega_{m}$&$\Omega_{r}$&$\Omega_{\Lambda}$\\
Different species &$\overbrace{\Omega_{b}\quad\Omega_{c}}^{}$&
 $\overbrace{\Omega_{\gamma}\quad\Omega_{\nu}}^{}$&
\end{tabular}

\end{document} 

在此处输入图片描述

答案2

我不太确定这是否可以通过 实现\overbrace。我认为\overbrace只能跨越同一数学环境中包含的事物(至少我没有找到任何表明相反情况的信息;但我承认我没有使用过这个特定命令的任何个人经验)。

我尝试了另一种方法,使用TikZ树。结果如下: 代码结果

代码:

    \documentclass[margin=3mm,tikz]{standalone}
\usetikzlibrary{decorations.pathreplacing}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}[
    level distance=10mm,
    level 1/.style={sibling distance=30mm},
    level 2/.style={sibling distance=15mm},
    ]
    % The main tree
    \node (omega) {$\Omega$} [draw=white]
        child {
            node (w_m) {$\Omega_{m}$}
            child {node (w_b) {$\Omega_{b}$}}
            child {node (w_c) {$\Omega_{c}$}}
        }
        child {
            node (w_r) {$\Omega_{r}$}
            child {node (w_gamma) {$\Omega_{\gamma}$}}
            child {node (w_nu)    {$\Omega_{\nu}$}}
        }
        child {node (w_lambda) {$\Omega_{\Lambda}$}}
    ;

    \begin{scope}[
        every path/.append style={
            decorate,decoration={brace,raise=2mm}}
        ]
        \draw (w_m.north west)     -- (w_lambda.north east);
        \draw (w_b.north west)     -- (w_c.north east);
        \draw (w_gamma.north west) -- (w_nu.north east);
    \end{scope}

    % Text on left  side is put in a tree  as well, thus
    % ensuring that the vertical spacing is identical to
    % the actual tree.
    \begin{scope}[
        every node/.append style={
            text width=50mm,
            align=left,
            draw=none
            },
            every child/.append style={draw=white},
        ]
        \node[left=50mm of omega] (tot_matter) {Total Matter}
            child {
                node (d_eqs) {Different equations of state}
                child {node (d_species) {Different species}}
            }
            ;
    \end{scope}

    % Vertical separator line
    \draw (tot_matter.north east) -- (d_species.south east);

\end{tikzpicture}
\end{document}

这个例子中的放置是手工完成的,当然有点粗糙,还可以进行进一步的优化,但你明白了。

杰克在这个回答中更详细地介绍了brace装饰:TikZhttps://tex.stackexchange.com/a/34450/131649

您还可以在 PGF 手册第 21 节中找到有关它的更多信息 -让树木生长,第 316 页及以下: http://mirrors.ctan.org/graphics/pgf/base/doc/pgfmanual.pdf

当然,如果有一种好的方法,只需通过表格和一些缩放良好的括号即可做到这一点,那可能会更容易。用于绘制树的好处TikZ是它们非常容易缩放。但不可否认的是,并非每种情况都需要这样做。

哦,欢迎来到 TeX.sx!

答案3

如果它是一棵树,它可以成为一片森林....

\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{decorations.pathreplacing}
\usepackage{forest}
\begin{document}
\begin{forest}
  for tree={
    math content,
    fit=band,
    edge path'={
      (.parent first) -- (!ul.parent last)
    },
    edge+={decorate, decoration={brace}},
    l sep'=0pt,
  },
  for n=1{
    tikz+={
      \node (n) [fit to=tree] {};
      \draw (n.north east) -- (n.south east);
    },
  },
  for nodewalk={
    1,
    descendants
  }{no edge, plain content, anchor=mid west},
  for nodewalk={2,descendants}{
    before typesetting nodes={
      if content={}{
        content=\Omega
      }{
        content/.wrap value=\Omega_{#1},
        before packing={
          text width/.process={OOPw3{max x}{min x}{width("$\Omega$")}{#3+.25*(#1-#2)}},
          text centered,
          typeset node,
        },
      },
      anchor=mid,
      if n=1{}{no edge},
    },
  },
  [, phantom
    [Total matter
      [Different equations of state
        [Different species]
      ]
    ]
    [
      [m
        [b]
        [c]
      ]
      [r
        [\gamma]
        [\nu]
      ]
      [\Lambda]
    ]
  ]
\end{forest}
\end{document}

支架边缘

答案4

使用 TABstacks(无需反复试验\raisebox

\documentclass{article}
\usepackage{tabstackengine,amsmath}
\TABstackMath% PROCESS TABstacks IN MATH MODE (REGULAR STACKS IN TEXT MODE)
%\fixTABwidth{T}% MAKE TABstack COLUMNS EQUAL WIDTH
\setstacktabbedgap{\tabcolsep}% GAP BETWEEN COLUMNS
\setstackgap{L}{1.8\normalbaselineskip}% BASELINESKIP BETWEEN ROWS
\renewcommand\stacktype{L}% DEFAULT TO "LONG" STACKS
\begin{document}
\begin{tabular}{c|c}
\Longunderstack[l]{Total matter\\Different equations of state\\Different species}
&
\stackunder{$\Omega$}{$\overbrace{\tabbedLongunderstack{
  \Omega_m & \Omega_r & \Omega_\Lambda\\
  \overbrace{\Omega_b\quad\Omega_c}&
  \overbrace{\Omega_\gamma\quad\Omega_\nu}&
}}$}
\end{tabular}
\end{document}

在此处输入图片描述

如果我取消注释序言中的一行,以强制所有列宽相等,

在此处输入图片描述

相关内容