TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

in the code given below, I wanted the brackets from the \blkarray matrix to match those of the original matrix given in Equ (1).

enter image description here

The issue is, when I use the \blkarray, the brackets are too short and does not look as elegant as in the original matrix. Can this be fixed? Thanks.

Here is the code that was elegantly devised by cfr:

\documentclass[11pt]{book}

\usepackage{amsmath,amsfonts,amssymb,amsthm}
\usepackage{xcolor}
\definecolor{ocre}{RGB}{0,173,239}

\usepackage{blkarray}

\makeatletter
\renewcommand*\env@matrix[1][*\c@MaxMatrixCols c]{%
  \hskip -\arraycolsep
  \let\@ifnextchar\new@ifnextchar
  \array{#1}}
\makeatother

\usepackage{tikz}

\usetikzlibrary{arrows,matrix,positioning,fit,arrows.meta,}
\tikzset{%
  highlight/.style={rectangle,rounded corners,fill=ocre!50,draw,
    fill opacity=0.5,thick,inner sep=0pt}
}
\newcommand{\tikzmark}[2]{\tikz[overlay,remember picture,
  baseline=(#1.base)] \node (#1) {#2};}
%
\newcommand{\Highlight}[1][submatrix]{%
    \tikz[overlay,remember picture]{
    \node[highlight,fit=(left.north west) (right.south east)] (#1) {};}
}
\newcommand{\mytikzmark}[2]{\tikz[overlay,remember picture, baseline=(#1.base)] \node (#1) {#2};}
\begin{document}

Original Matrix:

\begin{equation}
\begin{bmatrix}[cccc|c]
  1 & 0 & -1 & 0 & 0 \\
  0 & 1 & 2 & 0 & 0 \\
  0 & 0 & 0 & 1 & 0
\end{bmatrix}\\
\end{equation}

Updated Matrix:

\begin{equation}
  \begin{blockarray}{ccccc}
    x_{1} & x_{2} & x_{3} & x_{4} &  \\
    \begin{block}{[cccc|c]}
      1 & 0 & \mytikzmark{left}{-1} & 0 & 0 \\
      0 & 1 & 2 & 0 & 0 \\
      0 & 0 & \mytikzmark{right}{0} & 1 & 0 \\
    \end{block}
  \end{blockarray}
  \Highlight[new1]
\end{equation}
\tikz[remember picture,overlay]{%
  \draw [LaTeX-] (new1.south) ++(0,-2.5pt) [out=-90,in=160] to ++(5mm,-10mm) node [right, xshift=-2.5mm, font=\itshape, text=red, align=center] {free\\variable};
}

\end{document} 
share|improve this question
up vote 3 down vote accepted

You might use \bbordermatrix from \bordermatrix with brackets [ ] instead of parentheses ( )

\documentclass{article}
\usepackage{xcolor}
\usepackage{tikz}
\usepackage{etoolbox}

\usetikzlibrary{arrows,matrix,positioning,fit,arrows.meta,}

\definecolor{ocre}{RGB}{0,173,239}

\tikzset{%
  highlight/.style={rectangle,rounded corners,fill=ocre!50,draw,
    fill opacity=0.5,thick,inner sep=0pt}
}
\newcommand{\tikzmark}[2]{\tikz[overlay,remember picture,
  baseline=(#1.base)] \node (#1) {#2};}
%
\newcommand{\Highlight}[1][submatrix]{%
    \tikz[overlay,remember picture]{
    \node[highlight,fit=(left.north west) (right.south east)] (#1) {};}
}
\newcommand{\mytikzmark}[2]{\tikz[overlay,remember picture, baseline=(#1.base)] \node (#1) {#2};}

\let\bbordermatrix\bordermatrix
\patchcmd{\bbordermatrix}{8.75}{4.75}{}{}
\patchcmd{\bbordermatrix}{\left(}{\left[}{}{}
\patchcmd{\bbordermatrix}{\right)}{\right]}{}{}

\newcommand{\wall}[2]{%
  \smash{%
    \vrule height \dimexpr\ht\strutbox+#1 depth \dimexpr\dp\strutbox+#2\relax
  }%
}

\begin{document}
\begin{equation}
\bbordermatrix{
 & x_{1} & x_{2} & x_{3}                 & x_{4} &                 &   \cr
 & 1     & 0     & \mytikzmark{left}{-1} & 0     & \wall{0pt}{3pt} & 0 \cr
 & 0     & 1     & 2                     & 0     & \wall{3pt}{3pt} & 0 \cr
 & 0     & 0     & \mytikzmark{right}{0} & 1     & \wall{3pt}{0pt} & 0 \cr
}
\Highlight[new1]
\end{equation}
\tikz[remember picture,overlay]{%
  \draw [LaTeX-] (new1.south) ++(0,-2.5pt) [out=-90,in=160] to ++(5mm,-10mm) node [right, xshift=-2.5mm, font=\itshape, text=red, align=center] {free\\variable};
}

\end{document}

enter image description here

share|improve this answer

This is rather close to just re-asking the same question but if you want to highlight a column in the first array rather than the second, just put the marks there.

enter image description here

Or egreg wants me to do this

enter image description here

\documentclass[11pt]{book}


\documentclass[11pt]{book}

\usepackage{amsmath,amsfonts,amssymb,amsthm}
\usepackage{xcolor}
\definecolor{ocre}{RGB}{0,173,239}

\usepackage{blkarray}

\makeatletter
\renewcommand*\env@matrix[1][*\c@MaxMatrixCols c]{%
  \hskip -\arraycolsep
  \let\@ifnextchar\new@ifnextchar
  \array{#1}}
\makeatother

\usepackage{tikz}

\usetikzlibrary{arrows,matrix,positioning,fit,arrows.meta,}
\tikzset{%
  highlight/.style={rectangle,rounded corners,fill=ocre!50,draw,
    fill opacity=0.5,thick,inner sep=0pt}
}
\newcommand{\tikzmark}[2]{\tikz[overlay,remember picture,
  baseline=(#1.base)] \node (#1) {#2};}
%
\newcommand{\Highlight}[1][submatrix]{%
    \tikz[overlay,remember picture]{
    \node[highlight,fit=(left.north west) (right.south east)] (#1) {};}
}
\newcommand{\mytikzmark}[2]{\tikz[overlay,remember picture, baseline=(#1.base)] \node (#1) {#2};}
\begin{document}

Original Matrix:



\bigskip
\begin{equation}
\begin{bmatrix}[cccc|c]
\noalign{\vskip-1.5\normalbaselineskip}
  x_{1} & x_{2} & x_{3} &\multicolumn{1}{c}{ x_{4}} &  \\
\noalign{\vskip.5\normalbaselineskip}
  1 & 0 & \mytikzmark{left}{-1} & 0 & 0 \\
  0 & 1 & 2 & 0 & 0 \\
  0 & 0 & \mytikzmark{right}{0} & 1 & 0
\end{bmatrix}\\
\end{equation}

  \Highlight[new1]

\tikz[remember picture,overlay]{%
  \draw [LaTeX-] (new1.south) ++(0,-2.5pt) [out=-90,in=160] to ++(5mm,-10mm) node [right, xshift=-2.5mm, font=\itshape, text=red, align=center] {free\\variable};
}

\end{document} 
share|improve this answer
    
The question refers to the fact that the brackets in the blockarray are too short with respect to the material they bound. – egreg Feb 8 at 23:50
    
@egreg sure so the answer is to not use blkarray and put the highlights on a normal matrix if you prefer that as it doesn't depend on blkarray. – David Carlisle Feb 8 at 23:53
    
Note that the user wants to have a row above the blockarray – egreg Feb 8 at 23:55
    
@egreg that isn't clear from the question but the headings could be put back of course. – David Carlisle Feb 8 at 23:55

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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