3

MWE:

\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}

enter image description here

Does someone know how to achieve this without using tikzmark?

I have a document which relies heavily on tikzexternal to have an acceptable compilation time and afaik, tikzexternal and tikzmark are incompatible.

UPDATE
I have added to the MWE commented lines to activate tikzexternal. Uncommenting the lines with \usetikzlibrary{external}, \tikzexternalize and \tikzexternaldisable returns following errors:

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.
  • tikzmark requires a double compilation. Have you compiled your document twice with tikzmark? – AndréC Dec 12 '19 at 17:01
  • Yes, I did. I do not have a problem with tikzmark as long as I do not use tikzexternal. – Hotschke Dec 12 '19 at 17:25
  • Why not use a Tikz matrix? – AndréC Dec 12 '19 at 17:26
  • 1
    You could turn off externalisation just for tikzmarks. Would that be acceptable? – Loop Space Dec 12 '19 at 17:58
  • 1
    Also, you should use the tikzmark library rather than that command. – Loop Space Dec 12 '19 at 17:59
4

It is very simple with package bigdelim. I took the opportunity to simplify a bit your code:

\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} 

enter image description here

  • Thanks for your answer which looks like the shortest solution to my problem. – Hotschke Dec 13 '19 at 7:25
5

One can play around with the spacing a bit, but this does what you're after without a tikzmark:

enter image description here

\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}
2

Here's working code with 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}

The \tikzmark command has evolved considerably since the definition that you originally used, meaning that when using tikzmarks you have to use a different syntax. That's what was causing all the errors that you saw, and with those errors then the externalisation wouldn't have worked for the other pictures. Also, the command \tikzexternalize has to be in the preamble.

Another change is that the names used by tikzmark should now be unique through the document, so re-using generally doesn't work. To counter this, I added a counter to your brace code.

The ends of the braces will be a bit off, this is because the new tikzmarks don't take up any space and don't define anchors. Add a vertical shift to the upper end of the brace (probably \baselineskip would be best).

Incidentally, tikzmark and externalisation are incompatible because for a picture to be externalisable, it has to be contained within a definite box - both when being generated and when being included back in the main document. Tikzmarks are for exactly when that doesn't happen. I should probably add in a feature whereby externalisation is automatically turned off for tikzmarks since it makes no sense to even try to externalise a tikzmark.

  • Sorry to interrupt, but the OP mentioned he needs the requirement without using tikz... – MadyYuvi Dec 13 '19 at 5:27
  • @MadyYuvi On this site we try to be as helpful as possible, which includes providing alternatives that may not fit the OP's precise specification but which are close enough that someone with essentially the same question might find useful. Also, if you read the comments on the main question you'll see that I did ask if this would be an acceptable solution before posting it. – Loop Space Dec 13 '19 at 6:53
  • @LoopSpace: Thank you for your answer. It was definitely helpful and I probably go with your answer even though I specified without tikzmark. I like the answer by Werner (which I had as a second try myself): but I usually want to avoid to manually align things (defining the widest elements manually is necessary). The answer by MadyYuvi lost the alignment between blocks. I have to look into the answer by Bernard. I guess the size of bigdelim is also a manual value but probably less fragile than defining the widest element which can change more easily. – Hotschke Dec 13 '19 at 7:22
2

This may help you, in this I used mathtools package only:

\documentclass{article}
\usepackage{mathtools}
\renewcommand{\vec}[1]{\mathbf{#1}}

\newcommand{\DeclareAutoPairedDelimiter}[3]{%Thanks to egreg for advising this
  \expandafter\DeclarePairedDelimiter\csname Auto\string#1\endcsname{#2}{#3}%
  \begingroup\edef\x{\endgroup
    \noexpand\DeclareRobustCommand{\noexpand#1}{%
      \expandafter\noexpand\csname Auto\string#1\endcsname*}}%
  \x}

\DeclareAutoPairedDelimiter{\sar}{[}{.}

\begin{document}


\begin{align*}
  \def\arraystretch{1.1}
    \mathcal{H} &=\begin{array}{rlll}&\phantom{\vec{a}-\vec{b},2\vec{a}+2\vec{b}} &p2mg\end{array}\\
&\quad  \begin{rcases}
\sar{    \begin{array}{@{}rlll@{}}
       & \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]
    \end{array}}\\
\sar{    \begin{array}{@{}rlll@{}}
       & \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}}
\end{rcases}\\
&\quad\begin{rcases}
\sar{    \begin{array}{@{}rlll@{}}
       & \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]
    \end{array}}\\
\sar{    \begin{array}{@{}rlll@{}}
       & \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}}
\end{rcases}
\end{align*}


\end{document}

Output

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.