矩阵下的圆括号

矩阵下的圆括号
\begin{flalign*}
&\left.
\begin{bmatrix}
x_{11} & \cdots & x_{1k} \\
\vdots & \ddots & \vdots \\
x_{n1} & \cdots & x_{nk} 
\end{bmatrix}
\right)~\text{$n$ observations}&
\end{flalign*}

在此处输入图片描述

我想在带有文本“k 个变量”的矩阵下方绘制一个圆括号。我知道如何在矩阵的左侧和右侧绘制圆括号,但我不知道如何在矩阵下方绘制它。

答案1

最后编辑:[所有三种方式(第四种只是半自动化第二种方式)]

\documentclass{article}

\usepackage{mathtools}
\usepackage{tikz}
\usepackage{anyfontsize}
\usetikzlibrary{arrows,matrix,positioning,decorations.pathreplacing,calc}


\makeatletter
\newcommand\getwidthofnode[2]{%
    \pgfextractx{#1}{\pgfpointanchor{#2}{east}}%
    \pgfextractx{\pgf@xa}{\pgfpointanchor{#2}{west}}% \pgf@xa is a length defined by PGF for temporary storage. No need to create a new temporary length.
    \addtolength{#1}{-\pgf@xa}%
}
\makeatother

\makeatletter
\newcommand\getheightofnode[2]{%
    \pgfextracty{#1}{\pgfpointanchor{#2}{north}}%
    \pgfextracty{\pgf@ya}{\pgfpointanchor{#2}{south}}% \pgf@xa is a length defined by PGF for temporary storage. No need to create a new temporary length.
    \addtolength{#1}{-\pgf@ya}%
}
\makeatother

\newlength\TestLength
\newlength\TestHeight
\begin{document}


% First way: No tikz but a \vphantom "trick" for the \right) 
First way:

$\underbrace{\begin{aligned}
\begin{bmatrix}
x_{11} & \cdots & x_{1k} \\
\vdots & \ddots & \vdots \\
x_{n1} & \cdots & x_{nk} 
\end{bmatrix}\end{aligned}
}_{k~\text{variables}}
\left.\vphantom{\begin{aligned}
\begin{bmatrix}
x_{11} & \cdots & x_{1k} \\
\vdots & \ddots & \vdots \\
x_{n1} & \cdots & x_{nk} 
\end{bmatrix}\end{aligned}}\right)~\text{$n$ observations}$
\vspace*{15pt}

% Second way: tikz and brace ( manual fix of shifting)
Second way:

\begin{tikzpicture}
   \node (m1) at (0,0) {$\begin{aligned}
\begin{bmatrix}
x_{11} & \cdots & x_{1k} \\
\vdots & \ddots & \vdots \\
x_{n1} & \cdots & x_{nk} 
\end{bmatrix}\end{aligned}$};
\draw [thick,decorate,decoration={brace,amplitude=6pt,mirror}] ([xshift=10pt]m1.south west) -- 
([xshift=-10pt]m1.south east) node[midway] (m2) {};
\node [anchor=north,yshift=-6pt] at (m2) {$k$ variables};
\draw[thick,decorate,decoration={brace,amplitude=6pt,mirror}] ([yshift=6pt]m1.south east) --
([yshift=-6pt]m1.north east) node[midway] (m3) {};
\node[anchor=west,xshift=6pt] at (m3) {$n$ observations};
\end{tikzpicture}
\vspace*{15pt}

% Third way: tikz and round bracket (using "\getwidthofnode" and "\getheightofnode" to automate procedure)
Third way: 

\begin{tikzpicture}
   \node (m1) at (0,0) {$\begin{aligned}
\begin{bmatrix}
x_{11} & \cdots & x_{1k} \\
\vdots & \ddots & \vdots \\
x_{n1} & \cdots & x_{nk} 
\end{bmatrix}\end{aligned}$};
\getwidthofnode{\TestLength}{m1}
\pgfmathsetmacro\myLength{\TestLength*0.7}
\node (m2)[yscale=0.5,rotate=-90,font=\fontsize{\myLength}{45}\selectfont] at (m1.south) {)};%yscale here is to reduce width of horizontal ")"
\node [anchor=north] at (m2) {$k$ variables};
\getheightofnode{\TestHeight}{m1}
\pgfmathsetmacro\myLength{\TestHeight*0.7}
\node (m3) [xscale=0.8,font=\fontsize{\myLength}{45}\selectfont] at ($(m1)+(\TestLength/2,0)$) {)};%xscale here is to reduce width of vertical ")"
\node (m4) at (m3) {\phantom{$n$ observations}};
\getwidthofnode{\TestLength}{m4}
\node at ($(m4)+(\TestLength/2,0)$) {$n$ observations};
\end{tikzpicture}
\vspace*{15pt}

% Fourth way: tikz and brace (using "\getwidthofnode" and "\getheightofnode" to semi-automate procedure)
Fourth way:

\begin{tikzpicture}
\xdef\MatrixToBraceXSouthScale{0.7}
\xdef\MatrixToBraceYEastScale{0.7}
   \node (m1) at (0,0) {$\begin{aligned}
\begin{bmatrix}
x_{11} & \cdots & x_{1k} \\
\vdots & \ddots & \vdots \\
x_{n1} & \cdots & x_{nk} 
\end{bmatrix}\end{aligned}$};
\getwidthofnode{\TestLength}{m1}
\pgfmathsetmacro\myWidth{\TestLength/2}
\getheightofnode{\TestLength}{m1}
\pgfmathsetmacro\myHeight{\TestLength/2}
\draw [thick,decorate,decoration={brace,amplitude=6pt,mirror}]  ($(m1)-({\myWidth*\MatrixToBraceXSouthScale pt},{\myHeight pt})$)--
($(m1)+({\myWidth*\MatrixToBraceXSouthScale pt},{-\myHeight pt})$) node[midway](m2) {};
\node [anchor=north,yshift=-7pt] at (m2) {$k$ variables};
\draw [thick,decorate,decoration={brace,amplitude=6pt,mirror}] ($(m1)+({\myWidth pt},{-\myHeight*\MatrixToBraceYEastScale pt})$)--
($(m1)+({\myWidth pt},{\myHeight*\MatrixToBraceYEastScale pt})$) node [midway](m3){};
\node[anchor=west,xshift=6pt] at (m3) {$n$ observations};
\end{tikzpicture}


\end{document}

使用@Caramdir 的解决方案tikzpicture 中的 \widthof

结果:

在此处输入图片描述

答案2

您可以使用abraces包。如果你将 bmatrix 包装进去,\aunderbrace[l1r]{}你就会得到我认为你想要的东西。你可以像使用其他括号一样使用这个括号香草下括号,使用_^在其上添加上标或下标。

请参阅此处问题的答案https://tex.stackexchange.com/a/132527/54688

\documentclass{article}
\usepackage{mathtools}% http://ctan.org/pkg/mathtools
\usepackage{abraces}% http://ctan.org/pkg/abraces
\begin{document}
  \begin{flalign*}
    \aunderbrace[l1r]{%
      \begin{bmatrix}
      x_{11} & \cdots & x_{1k} \\
      \vdots & \ddots & \vdots \\
      x_{n1} & \cdots & x_{nk}
      \end{bmatrix}
    }_{k~\text{variables}}
  \end{flalign*}
\end{document}

答案3

我的答案是迄今为止这里揭示的所有答案的组合。

在此处输入图片描述

\documentclass{article}
\usepackage{amsmath,amsfonts}
\usepackage[overload]{abraces}

\let\underfence\underbrace

\begin{document}

\[
X=
\underfence[l1r]{%
    \begin{aligned}
        \begin{bmatrix}
        x_{11} & \cdots & x_{1k} \\
        \vdots & \ddots & \vdots \\
        x_{n1} & \cdots & x_{nk} 
        \end{bmatrix} \\[1ex]
    \end{aligned}
}_{k~\text{variables}}
\left.\vphantom{%
    \begin{aligned}
        \begin{bmatrix}
        x_{11} & \cdots & x_{1k} \\
        \vdots & \ddots & \vdots \\
        x_{n1} & \cdots & x_{nk} 
        \end{bmatrix}
    \end{aligned}
}\right)~\text{\scriptsize $n$ observations}
\]

\end{document}

更新日期 2018/01/04

申请Martin Scharrer 的这个回答得到矩阵

在此处输入图片描述

矩阵由括号分隔,括号根据包含它的不可见边界框定位。

在此处输入图片描述

代码

\documentclass[border=4mm,tikz]{standalone}
\usepackage{amsmath}
  \usetikzlibrary{matrix}

\begin{document}

\tikzset{
  withparens/.style = {%
    %draw=red,
    outer sep=0pt,
    right delimiter=),
    below delimiter=),
    align=center},
}

\begin{tikzpicture}
    \node (m1) [right=1.5cm, withparens] {%
        $\begin{bmatrix}
        x_{11} & \cdots & x_{1k} \\
        \vdots & \ddots & \vdots \\
        x_{n1} & \cdots & x_{nk} 
        \end{bmatrix}$
        };
\node [anchor=north, yshift=-1.1cm] at (m1) {$k$ variables};
\node [anchor=west, xshift=1.8cm] at (m1) {$n$ observations};
\end{tikzpicture}

\end{document}

相关内容