表格环境中的括号

表格环境中的括号

我想创建一个美观的表格,表格内有一些案例。我想像往常一样从左侧用括号表示案例,如下图所示(取自http://en.wikibooks.org/wiki/LaTeX/Advanced_Mathematics):

括号示例

我的 MWE 如下:

\documentclass[a4paper,12pt]{report}
\usepackage{booktabs}
\usepackage{multirow}

\begin{document}
\begin{table}
\centering
\begin{tabular}{lclr}
\toprule[1.5pt]
{ID} & {\#} & {Behaviour} & {Ave. peak} \\
\midrule
\multirow{4}{*}{\emph{dog} \Bigg\{ } & 1 & $1^{\mathrm{st}}$ torsion  & 12.3251 \\
 & 2 & $1^{\mathrm{st}}$ out-of-plane bending & 24.1345 \\
 & 3 & $1^{\mathrm{st}}$ in-plane bending & 54.1341 \\
 & 4 & $2^{\mathrm{nd}}$ torsion & 12.1234 \\[5pt]

\emph{kitten} & 1 & $1^{\mathrm{st}}$ torsion & 34.5431 \\

\bottomrule[1.5pt]
\end{tabular}
\end{table}
\end{document}

渲染为:

渲染图像

问题只在于括号的大小,因为在这种情况下它应该是 4 行高,在其他情况下应该是 5 行高,等等,动态的。

提前谢谢你,亚当

答案1

您可以通过以下两种方式执行此操作:

  1. 大号支架

    您可以根据需要指定更大的括号关于大括号大于 Bigg实现:

    在此处输入图片描述

    但这确实需要手动干预来选择支架的尺寸。

  2. \tikzmark

    或者,您可以使用tikzmark标记括号的重要点,然后使用tikz绘制括号。这样更灵活,因为如果您添加/减去行,则无需调整代码,而且在绘制括号的方式方面提供了更大的灵活性:

    在此处输入图片描述

笔记:

  • 在这两种解决方案中,我都调整了列间距。如果不需要,请将其删除。

  • \tikzmark解决方案确实需要运行两次。第一次确定位置,第二次进行绘图。

  • 来自\tikzmark在正文旁边添加大括号


代码Bigger that \Big

\documentclass[a4paper,12pt]{report}
\usepackage{amsmath}
\usepackage{booktabs}
\usepackage{multirow}

% https://tex.stackexchange.com/questions/6794/about-big-parenthesis-larger-than-bigg
\makeatletter
    \newcommand{\vast}{\bBigg@{3}}
    \newcommand{\Vast}{\bBigg@{3.5}}
    \newcommand{\vastt}{\bBigg@{4}}
    \newcommand{\Vastt}{\bBigg@{4.5}}
    %%
    %% Size from smallest to largest:
    %%\[ ( \big( \Big( \bigg( \Bigg( \vast( \Vast( \vastt( \Vastt(\]
\makeatother


\begin{document}
\begin{table}
\centering
\begin{tabular}{l@{\hspace*{0.5em}}clr}% <-- @{} adjusted inter column space
\toprule[1.5pt]
{ID} & {\#} & {Behaviour} & {Ave. peak} \\
\midrule
\multirow{4}{*}{\emph{dog} \vastt\{ } & 1 & $1^{\mathrm{st}}$ torsion  & 12.3251 \\
 & 2 & $1^{\mathrm{st}}$ out-of-plane bending & 24.1345 \\
 & 3 & $1^{\mathrm{st}}$ in-plane bending & 54.1341 \\
 & 4 & $2^{\mathrm{nd}}$ torsion & 12.1234 \\[5pt]

\emph{kitten} & 1 & $1^{\mathrm{st}}$ torsion & 34.5431 \\

\bottomrule[1.5pt]
\end{tabular}
\end{table}
\end{document}

代码:\tikzmark

\documentclass[a4paper,12pt]{report}
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{xparse}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{decorations.pathreplacing}

\newcommand{\tikzmark}[1]{\tikz[overlay,remember picture] \node (#1) {};}

\newcommand*{\BraceAmplitude}{0.4em}%
\newcommand*{\VerticalOffset}{0.5ex}%  
\newcommand*{\HorizontalOffset}{1.0em}% 
\NewDocumentCommand{\InsertLeftBrace}{%
    O{} % #1 = draw options
    O{\HorizontalOffset,\VerticalOffset} % #2 = optional brace shift options
    m   % #3 = top tikzmark
    m   % #4 = center tikzmark
    m   % #5 = bottom tikzmark
}{%
    \begin{tikzpicture}[overlay,remember picture]
        \coordinate (Brace Top)    at ($(#4 |- #3.north) + (#2)$);
        \coordinate (Brace Bottom) at ($(#4 |- #5.south) + (#2)$);
    \draw [decoration={brace, amplitude=\BraceAmplitude}, decorate, thick, draw=blue, #1]
    (Brace Bottom) -- (Brace Top) ;
    \end{tikzpicture}%
}%


\begin{document}
\begin{table}
\centering
\begin{tabular}{l@{\hspace*{0.5em}}clr}% <-- @{} adjusted inter column space
\toprule[1.5pt]
{ID} & {\#} & {Behaviour} & {Ave. peak} \\
\midrule
\multirow{4}{*}{\emph{dog}\tikzmark{Center Mark}} & \tikzmark{Top Mark}1 & 
        $1^{\mathrm{st}}$ torsion  & 12.3251 \\
 & 2 & $1^{\mathrm{st}}$ out-of-plane bending & 24.1345 \\
 & 3 & $1^{\mathrm{st}}$ in-plane bending & 54.1341 \\
 & \tikzmark{Bottom Mark}4 & $2^{\mathrm{nd}}$ torsion & 12.1234 \\[5pt]

\emph{kitten} & 1 & $1^{\mathrm{st}}$ torsion & 34.5431 \\

\bottomrule[1.5pt]
\end{tabular}
\InsertLeftBrace[red, ultra thick]{Top Mark}{Center Mark}{Bottom Mark}
\end{table}
\end{document}

答案2

使用{NiceTabular}ofnicematrix及其内置命令\SubMatrix

\documentclass[a4paper,12pt]{report}
\usepackage{nicematrix}
\usepackage{booktabs}

\begin{document}

\begin{table}
\centering
\begin{NiceTabular}{lclr}
    \toprule
    ID & \# & Behaviour & Ave. peak \\
    \midrule
    \Block{4-1}{\emph{dog}}
     & 1 & $1^{\mathrm{st}}$ torsion  & 12.3251 \\
     & 2 & $1^{\mathrm{st}}$ out-of-plane bending & 24.1345 \\
     & 3 & $1^{\mathrm{st}}$ in-plane bending & 54.1341 \\
     & 4 & $2^{\mathrm{nd}}$ torsion & 12.1234 \\[5pt]

    \emph{kitten} & 1 & $1^{\mathrm{st}}$ torsion & 34.5431 \\
    \bottomrule
\CodeAfter
    \SubMatrix{\{}{2-2}{5-2}{.}
\end{NiceTabular}
\end{table}

\end{document}

上述代码的输出

相关内容