左右括号括起不同数量的行,无 tikzmark

左右括号括起不同数量的行,无 tikzmark

梅威瑟:

\documentclass{article}
\usepackage{blkarray}
\usepackage{amsmath}
\usepackage{tikz}
\usepackage{xparse}
\usetikzlibrary{decorations.pathreplacing,calc,tikzmark}
% \usetikzlibrary{external}
\newcommand*{\BraceAmplitude}{0.4em}
\newcommand*{\VerticalOffset}{1mm}
\newcommand*{\HorizontalOffset}{-1mm}
\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=black, #1]
        (Brace Bottom) -- (Brace Top);
    \end{tikzpicture}%
}
\NewDocumentCommand{\InsertRightBrace}{%
    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, mirror}, decorate, thick, draw=black, #1]
        (Brace Bottom) -- (Brace Top);
    \end{tikzpicture}%
}
\newcommand{\tp}{\tikzmark{Top}}
\newcommand{\tc}{\tikzmark{Center}}
\newcommand{\tb}{\tikzmark{Bottom}}


\renewcommand{\vec}[1]{\mathbf{#1}}
\begin{document}

% \tikzexternalize % activate

\begin{tikzpicture}
    \node at (0,0) {a tikz picture};
\end{tikzpicture}

% \tikzexternaldisable % disable for tikzmark

\begin{equation*}
  \def\arraystretch{1.1}
  \begin{blockarray}{r@{\;}ccc}
    \mathcal{H} = & \BAmulticolumn{3}{c}{p2mg} \\[\jot]
    \begin{block}{r@{\;}[lll}
       & \vec{a}-\vec{b},2\vec{a}+2\vec{b} & \frac{1}{2},0 & = \mathcal{H}_{31} \tp \\[\jot]
       & \vec{a}+2\vec{b},-2\vec{a} & 0,\frac{1}{2} & = \mathcal{H}_{31}' \\[\jot]
       & 2\vec{a}+\vec{b},2\vec{b} & \frac{1}{2},\frac{1}{2} & = \mathcal{H}_{31}'' \\[\jot]
    \end{block}
    \begin{block}{r@{\;}[lll}
       & \vec{a}-\vec{b},2\vec{a}+2\vec{b} & 1,\frac{1}{2} & = \mathcal{H}_{31}''' \\[\jot]
       & \vec{a}+2\vec{b},-2\vec{a} & -\frac{1}{2},\frac{1}{2} & = \mathcal{H}_{31}'''' \\[\jot]
       & 2\vec{a}+\vec{b},2\vec{b} & \frac{1}{2},1 & = \mathcal{H}_{31}''''' \;\tc\tb%
       \InsertRightBrace{Top}{Center}{Bottom}\\[\jot]
    \end{block}
    \begin{block}{r@{\;}[lll}
       & \vec{a}+\vec{b},-2\vec{a}+2\vec{b} & \frac{1}{2},0 & = \mathcal{H}_{32} \tp \\[\jot]
       & -\vec{a},-2\vec{a}-4\vec{b} & 0,\frac{1}{2} & = \mathcal{H}_{32}' \\[\jot]
       & \vec{b},-4\vec{a}-2\vec{b} & \frac{1}{2},\frac{1}{2} & = \mathcal{H}_{32}'' \\[\jot]
    \end{block}
    \begin{block}{r@{\;}[lll}
       & \vec{a}+\vec{b},-2\vec{a}+2\vec{b} & 0,\frac{1}{2} & = \mathcal{H}_{32}''' \\[\jot]
       & -\vec{a},-2\vec{a}-4\vec{b} & -\frac{1}{2},-\frac{1}{2} & = \mathcal{H}_{32}'''' \\[\jot]
       & \vec{b},-4\vec{a}-2\vec{b} & -\frac{1}{2},0 & = \mathcal{H}_{32}''''' \;\tc\tb%
       \InsertRightBrace{Top}{Center}{Bottom}\\[\jot]
    \end{block}
  \end{blockarray}
\end{equation*}

% \tikzexternalize % re-activate

\begin{tikzpicture}
    \node at (0,0) {another tikz picture};
\end{tikzpicture}

\end{document}

在此处输入图片描述

有人知道不用如何实现这一点吗tikzmark

我有一个文档,它严重依赖于tikzexternal可接受的编译时间和据我所知,tikzexternal并且tikzmark不兼容。

更新
我已将注释行添加到 MWE 以激活tikzexternal。用 取消注释行\usetikzlibrary{external}\tikzexternalize\tikzexternaldisable返回以下错误:

demo-blkarray.tex|68 error| Package pgf Error: No shape named Center is known.
demo-blkarray.tex|68 error| Package pgf Error: No shape named Top is known.
demo-blkarray.tex|68 error| Package pgf Error: No shape named Center is known.
demo-blkarray.tex|68 error| Package pgf Error: No shape named Bottom is known.
demo-blkarray.tex|79 error| Package pgf Error: No shape named Center is known.
demo-blkarray.tex|79 error| Package pgf Error: No shape named Top is known.
demo-blkarray.tex|79 error| Package pgf Error: No shape named Center is known.
demo-blkarray.tex|79 error| Package pgf Error: No shape named Bottom is known.

答案1

使用 package 非常简单bigdelim。我借此机会简化了你的代码:

\documentclass{article}
\usepackage{blkarray}
\usepackage{amsmath}
\usepackage{tikz}
\usepackage{xparse}
\renewcommand{\vec}[1]{\mathbf{#1}}
\usepackage{bigdelim}

\begin{document}

\begin{equation*}
  \def\arraystretch{1.1}\setlength{\BAextrarowheight}{\jot}
  \begin{blockarray}{r@{\;}ccc@{\!}c}
    \mathcal{H} = & \BAmulticolumn{3}{c}{p2mg} \\
    \begin{block}{r@{\;}[lll@{\!}c}
       & \vec{a}-\vec{b},2\vec{a}+2\vec{b} & \frac{1}{2},0 & = \mathcal{H}_{31}& \rdelim\}{6.1}{0.5em} \\
       & \vec{a}+2\vec{b},-2\vec{a} & 0,\frac{1}{2} & = \mathcal{H}_{31}' \\
       & 2\vec{a}+\vec{b},2\vec{b} & \frac{1}{2},\frac{1}{2} & = \mathcal{H}_{31}'' \\
    \end{block}
    \begin{block}{r@{\;}[lll@{\!}c}
       & \vec{a}-\vec{b},2\vec{a}+2\vec{b} & 1,\frac{1}{2} & = \mathcal{H}_{31}''' \\
       & \vec{a}+2\vec{b},-2\vec{a} & -\frac{1}{2},\frac{1}{2} & = \mathcal{H}_{31}'''' \\
       & 2\vec{a}+\vec{b},2\vec{b} & \frac{1}{2},1 & = \mathcal{H}_{31}''''' \\
    \end{block}
    \begin{block}{r@{\;}[lll@{\!}c}
       & \vec{a}+\vec{b},-2\vec{a}+2\vec{b} & \frac{1}{2},0 & = \mathcal{H}_{32} & \rdelim\}{6.1}{0.5em} \\
       & -\vec{a},-2\vec{a}-4\vec{b} & 0,\frac{1}{2} & = \mathcal{H}_{32}' \\
       & \vec{b},-4\vec{a}-2\vec{b} & \frac{1}{2},\frac{1}{2} & = \mathcal{H}_{32}'' \\
    \end{block}
    \begin{block}{r@{\;}[lll@{\!}c}
       & \vec{a}+\vec{b},-2\vec{a}+2\vec{b} & 0,\frac{1}{2} & = \mathcal{H}_{32}''' \\
       & -\vec{a},-2\vec{a}-4\vec{b} & -\frac{1}{2},-\frac{1}{2} & = \mathcal{H}_{32}'''' \\
       & \vec{b},-4\vec{a}-2\vec{b} & -\frac{1}{2},0 & = \mathcal{H}_{32}''''' \\
    \end{block}
  \end{blockarray}
\end{equation*}%

\end{document} 

在此处输入图片描述

答案2

你可以稍微调整一下间距,但是这可以实现你想要的效果,而不需要tikzmark

在此处输入图片描述

\documentclass{article}

\usepackage{array,amsmath}

\renewcommand{\vec}{\mathbf}

\newlength{\firstlen}
\newlength{\secondlen}
\newlength{\thirdlen}

\newcolumntype{P}[1]{>{$}p{#1}<{$}}
\settowidth{\firstlen}{$\vec{a} + \vec{b}, -2 \vec{a} + 2\vec{b}$}% Widest element in first column
\settowidth{\secondlen}{$-\frac{1}{2}, -\frac{1}{2}$} % Widest element in second column
\settowidth{\thirdlen}{${}= \mathcal{H}_{32}'''''$} % Widest element in third column

\begin{document}

\begin{align*}
  \mathcal{H} = & \makebox[20em]{p2mg} \\[\jot]
  & \begin{array}{ @{} l @{} }
    \left.\kern-\nulldelimiterspace
      \begin{array}{ @{} l @{} }
        \left[\begin{array}{ P{\firstlen} P{\secondlen} P{\thirdlen} }
           \vec{a} -  \vec{b},  2\vec{a} + 2\vec{b} & \frac{1}{2}, 0           & = \mathcal{H}_{31}   \\[\jot]
           \vec{a} + 2\vec{b}, -2\vec{a}            & 0, \frac{1}{2}           & = \mathcal{H}_{31}'  \\[\jot]
          2\vec{a} +  \vec{b},  2\vec{b}            & \frac{1}{2}, \frac{1}{2} & = \mathcal{H}_{31}''
        \end{array}\right.\kern-\nulldelimiterspace \\[7\jot]
        \left[\begin{array}{ P{\firstlen} P{\secondlen} P{\thirdlen} }
           \vec{a} -  \vec{b},  2\vec{a} + 2\vec{b} & 1, \frac{1}{2}            & = \mathcal{H}_{31}'''   \\[\jot]
           \vec{a} + 2\vec{b}, -2\vec{a}            & -\frac{1}{2}, \frac{1}{2} & = \mathcal{H}_{31}''''  \\[\jot]
          2\vec{a} +  \vec{b},  2\vec{b}            & \frac{1}{2}, 1            & = \mathcal{H}_{31}'''''
        \end{array}\right.\kern-\nulldelimiterspace
      \end{array}
    \right\} \\[15\jot]
    \left.\kern-\nulldelimiterspace
      \begin{array}{ @{} l @{} }
        \left[\begin{array}{ P{\firstlen} P{\secondlen} P{\thirdlen} }
           \vec{a} + \vec{b}, -2\vec{a} + 2\vec{b} & \frac{1}{2}, 0           & = \mathcal{H}_{32}   \\[\jot]
          -\vec{a}, -2\vec{a} - 4\vec{b}           & 0, \frac{1}{2}           & = \mathcal{H}_{32}'  \\[\jot]
           \vec{b}, -4\vec{a} - 2\vec{b}           & \frac{1}{2}, \frac{1}{2} & = \mathcal{H}_{32}''
        \end{array}\right.\kern-\nulldelimiterspace \\[7\jot]
        \left[\begin{array}{ P{\firstlen} P{\secondlen} P{\thirdlen} }
           \vec{a} + \vec{b}, -2\vec{a} + 2\vec{b} & 0, \frac{1}{2}             & = \mathcal{H}_{32}'''  \\[\jot]
          -\vec{a}, -2\vec{a} - 4\vec{b}           & -\frac{1}{2}, -\frac{1}{2} & = \mathcal{H}_{32}'''' \\[\jot]
           \vec{b}, -4\vec{a} - 2\vec{b}           & -\frac{1}{2}, 0            & = \mathcal{H}_{32}'''''
        \end{array}\right.\kern-\nulldelimiterspace
      \end{array}
    \right\}
  \end{array}
\end{align*}

\end{document}

答案3

以下是工作代码tikzmark

\documentclass{article}
%\url{https://tex.stackexchange.com/q/520211/86}
\usepackage{blkarray}
\usepackage{amsmath}
\usepackage{tikz}
\usepackage{xparse}
\usetikzlibrary{decorations.pathreplacing,calc,tikzmark}
\usetikzlibrary{external}
\newcommand*{\BraceAmplitude}{0.4em}
\newcommand*{\VerticalOffset}{1mm}
\newcommand*{\HorizontalOffset}{-1mm}
\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 ($({pic cs:#4-\thetikzmarkbrace} |- {pic cs:#3-\thetikzmarkbrace}) + (#2)$);
      \coordinate (Brace Bottom) at ($({pic cs:#4-\thetikzmarkbrace} |- {pic cs:#5-\thetikzmarkbrace}) + (#2)$);
      \draw[decoration={brace, amplitude=\BraceAmplitude}, decorate, thick, draw=black, #1]
        (Brace Bottom) -- (Brace Top);
    \end{tikzpicture}%
}
\NewDocumentCommand{\InsertRightBrace}{%
    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 ($({pic cs:#4-\thetikzmarkbrace} |- {pic cs:#3-\thetikzmarkbrace}) + (#2)$);
      \coordinate (Brace Bottom) at ($({pic cs:#4-\thetikzmarkbrace} |- {pic cs:#5-\thetikzmarkbrace}) + (#2)$);
      \draw[decoration={brace, amplitude=\BraceAmplitude, mirror}, decorate, thick, draw=black, #1]
        (Brace Bottom) -- (Brace Top);
    \end{tikzpicture}%
}

\newcounter{tikzmarkbrace}
\newcommand{\tp}{\stepcounter{tikzmarkbrace}\tikzmark{Top-\thetikzmarkbrace}}
\newcommand{\tc}{\tikzmark{Center-\thetikzmarkbrace}}
\newcommand{\tb}{\tikzmark{Bottom-\thetikzmarkbrace}}

\tikzexternalize % activate

\renewcommand{\vec}[1]{\mathbf{#1}}
\begin{document}


\begin{tikzpicture}
    \node at (0,0) {a tikz picture};
\end{tikzpicture}

\tikzexternaldisable % disable for tikzmark

\begin{equation*}
  \def\arraystretch{1.1}
  \begin{blockarray}{r@{\;}ccc}
    \mathcal{H} = & \BAmulticolumn{3}{c}{p2mg} \\[\jot]
    \begin{block}{r@{\;}[lll}
       & \vec{a}-\vec{b},2\vec{a}+2\vec{b} & \frac{1}{2},0 & = \mathcal{H}_{31} \tp \\[\jot]
       & \vec{a}+2\vec{b},-2\vec{a} & 0,\frac{1}{2} & = \mathcal{H}_{31}' \\[\jot]
       & 2\vec{a}+\vec{b},2\vec{b} & \frac{1}{2},\frac{1}{2} & = \mathcal{H}_{31}'' \\[\jot]
    \end{block}
    \begin{block}{r@{\;}[lll}
       & \vec{a}-\vec{b},2\vec{a}+2\vec{b} & 1,\frac{1}{2} & = \mathcal{H}_{31}''' \\[\jot]
       & \vec{a}+2\vec{b},-2\vec{a} & -\frac{1}{2},\frac{1}{2} & = \mathcal{H}_{31}'''' \\[\jot]
       & 2\vec{a}+\vec{b},2\vec{b} & \frac{1}{2},1 & = \mathcal{H}_{31}''''' \;\tc\tb%
       \InsertRightBrace{Top}{Center}{Bottom}\\[\jot]
    \end{block}
    \begin{block}{r@{\;}[lll}
       & \vec{a}+\vec{b},-2\vec{a}+2\vec{b} & \frac{1}{2},0 & = \mathcal{H}_{32} \tp \\[\jot]
       & -\vec{a},-2\vec{a}-4\vec{b} & 0,\frac{1}{2} & = \mathcal{H}_{32}' \\[\jot]
       & \vec{b},-4\vec{a}-2\vec{b} & \frac{1}{2},\frac{1}{2} & = \mathcal{H}_{32}'' \\[\jot]
    \end{block}
    \begin{block}{r@{\;}[lll}
       & \vec{a}+\vec{b},-2\vec{a}+2\vec{b} & 0,\frac{1}{2} & = \mathcal{H}_{32}''' \\[\jot]
       & -\vec{a},-2\vec{a}-4\vec{b} & -\frac{1}{2},-\frac{1}{2} & = \mathcal{H}_{32}'''' \\[\jot]
       & \vec{b},-4\vec{a}-2\vec{b} & -\frac{1}{2},0 & = \mathcal{H}_{32}''''' \;\tc\tb%
       \InsertRightBrace{Top}{Center}{Bottom}\\[\jot]
    \end{block}
  \end{blockarray}
\end{equation*}

\tikzexternalize % re-activate

\begin{tikzpicture}
    \node at (0,0) {another tikz picture};
\end{tikzpicture}

\end{document}

\tikzmark命令自您最初使用的定义以来已经发生了很大变化,这意味着在使用 tikzmarks 时,您必须使用不同的语法。这就是导致您看到的所有错误的原因,并且由于这些错误,外部化对其他图片不起作用。此外,该命令\tikzexternalize必须位于序言中。

另一个变化是,tikzmark 使用的名称现在在整个文档中应该是唯一的,因此重复使用通常不起作用。为了解决这个问题,我在你的括号代码中添加了一个计数器。

括号的末端会有点偏离,这是因为新的 tikzmarks 不占用任何空间,也不定义锚点。在括号的上端添加垂直偏移(可能\baselineskip是最好的)。

顺便说一句,tikzmark和外化是不兼容的,因为要使图片可外化,它必须包含在一个明确的框内 - 无论是在生成时还是在包含回主文档时。Tikzmarks 正是针对这种情况而设的。我可能应该添加一个功能,即外化自动地关闭 tikzmarks,因为尝试外部化 tikzmark 毫无意义。

答案4

具有{NiceArray}nicematrix它与 Tikz 的外部化过程兼容。

\documentclass{article}
\usepackage{nicematrix,tikz}
\usetikzlibrary{external}

\renewcommand{\vec}[1]{\mathbf{#1}}

\begin{document}

\tikzexternalenable

\begin{tikzpicture}
    \node at (0,0) {a tikz picture};
\end{tikzpicture}

\begin{equation*}
  \def\arraystretch{1.1}
  \begin{NiceArray}{r@{\;}ccl}
    \mathcal{H} = & \Block{1-3}{p2mg} \\[\jot]
       & \vec{a}-\vec{b},2\vec{a}+2\vec{b} & \frac{1}{2},0 & = \mathcal{H}_{31}  \\[\jot]
       & \vec{a}+2\vec{b},-2\vec{a} & 0,\frac{1}{2} & = \mathcal{H}_{31}' \\[\jot]
       & 2\vec{a}+\vec{b},2\vec{b} & \frac{1}{2},\frac{1}{2} & = \mathcal{H}_{31}'' \\[\jot]
       & \vec{a}-\vec{b},2\vec{a}+2\vec{b} & 1,\frac{1}{2} & = \mathcal{H}_{31}''' \\[\jot]
       & \vec{a}+2\vec{b},-2\vec{a} & -\frac{1}{2},\frac{1}{2} & = \mathcal{H}_{31}'''' \\[\jot]
       & 2\vec{a}+\vec{b},2\vec{b} & \frac{1}{2},1 & = \mathcal{H}_{31}''''' \\[\jot]
       & \vec{a}+\vec{b},-2\vec{a}+2\vec{b} & \frac{1}{2},0 & = \mathcal{H}_{32}  \\[\jot]
       & -\vec{a},-2\vec{a}-4\vec{b} & 0,\frac{1}{2} & = \mathcal{H}_{32}' \\[\jot]
       & \vec{b},-4\vec{a}-2\vec{b} & \frac{1}{2},\frac{1}{2} & = \mathcal{H}_{32}'' \\[\jot]
       & \vec{a}+\vec{b},-2\vec{a}+2\vec{b} & 0,\frac{1}{2} & = \mathcal{H}_{32}''' \\[\jot]
       & -\vec{a},-2\vec{a}-4\vec{b} & -\frac{1}{2},-\frac{1}{2} & = \mathcal{H}_{32}'''' \\[\jot]
       & \vec{b},-4\vec{a}-2\vec{b} & -\frac{1}{2},0 & = \mathcal{H}_{32}''''' 
  \CodeAfter
    \SubMatrix{[}{2-2}{4-2}{.}
    \SubMatrix{[}{5-2}{7-2}{.}
    \SubMatrix{[}{8-2}{10-2}{.}
    \SubMatrix{[}{11-2}{13-2}{.}
    \SubMatrix{.}{2-4}{7-4}{\}}
    \SubMatrix{.}{8-4}{13-4}{\}}
  \end{NiceArray}
\end{equation*}

\end{document}

您需要多次编译(因为nicematrix在后台使用 PGF/Tikz 节点)。

上述代码的输出

相关内容