Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have the following code to generate a matrix equation, on the LHS matrix, a couple of rules are added, that causes the RHS corresponding rows misaligned (vertically). How do I adjust subtle vspace in the RHS matrix if I'm sticking with the current code? Also is there a way to adjust the gray-scale of the rules (to make them less distracting)?

\documentclass{article}
\usepackage{mathtools}
% add vertical lines
\makeatletter
\renewcommand*\env@matrix[1][*\c@MaxMatrixCols c]{%
  \hskip -\arraycolsep
  \let\@ifnextchar\new@ifnextchar
  \array{#1}}
\makeatother
\usepackage{booktabs} % add horizontal lines
\usepackage{tikz}
\usetikzlibrary{arrows,shapes,matrix,positioning}
\newcommand{\tikzmark}[2]{\tikz[overlay, remember picture] \node[inner sep=0pt, outer sep=3pt, anchor=base] (#1) {#2};}

\begin{document}
\begin{equation}
  \begin{bmatrix}[cc|c|c|c|c]
\phantom{abcd}      & \phantom{ }       &       &       & 0     & \phantom{abcd}  \\
      &       &       &       & 0     &  \\
      &       &       &       & \cdots     &  \\
      &       &       &       & \cdots     &  \\ \cmidrule(lr){1-6}
      &       & a^{*}_{ts}     &       & 1     &  \\  \cmidrule(lr){1-6}
      &       &       &       & 0     &  \\
      &       &       &       & \cdots     &  \\
      &       &       &       & \cdots     &  \\
      &       &       &       & \cdots     &  \\
      &       &       &       & 0     &  \\
      &       &       &       & 0     &  \\  \cmidrule(lr){1-6}
      &       & \tikzmark{enter}{$c^{*}_s$}     &       & \tikzmark{leaving}{$c^{*}_t$}     &  \\
    \end{bmatrix}
    =
    \begin{bmatrix}
      \phantom{four} \\
 \\
 \\
 \\
b^{*}_t \\
 \\
 \\
 \\
 \\
 \\
 \\
 \\
-v \\
    \end{bmatrix}
\end{equation}
\tikz[overlay,remember picture] {
  \draw[<-,>=stealth] (enter) -- ++(0,-1cm) node [label={[xshift=-8pt,yshift=-20pt]entering}] {};
  \draw[<-,>=stealth] (leaving) -- ++(0,-1cm) node[label={[xshift=8pt,yshift=-20pt]leaving}] {};
}
\end{document}

enter image description here

share|improve this question
    
When you use \midrule vertical rules don't connect; why don't you use \hline? –  egreg Jun 4 at 21:49
    
@egreg hline leaves no space to the delimiters [1]: i.stack.imgur.com/tz3qL.jpg –  Jindan Zhou Jun 4 at 21:59
    
Yes, that's a small problem. You solve it by using \left[\begin{array}{@{}cc|c|c|c|c@{}} and \end{array}\right] at the end. –  egreg Jun 4 at 22:01

1 Answer 1

up vote 3 down vote accepted

In this case, array is more flexible:

\documentclass{article}
\usepackage{mathtools}
\usepackage{tikz}
\usetikzlibrary{arrows,shapes,matrix,positioning}
\newcommand{\tikzmark}[2]{\tikz[overlay, remember picture] \node[inner sep=0pt, outer sep=3pt, anchor=base] (#1) {#2};}

\begin{document}
\begin{equation}
\left[
\begin{array}{@{\qquad}|c|@{\quad}|c|@{\qquad}}
           & 0      \\
           & 0      \\
           & \cdots \\
           & \cdots \\ \hline
a^{*}_{ts} & 1      \\ \hline
           & 0      \\
           & \cdots \\
           & \cdots \\
           & \cdots \\
           & 0      \\
           & 0      \\ \hline
\tikzmark{enter}{$c^{*}_s$} & \tikzmark{leaving}{$c^{*}_t$}
\end{array}
\right]
=
\left[\begin{array}{@{}c@{}}
\\ \\ \\ \\
b^{*}_t \\
\\ \\ \\ \\ \\ \\
-v
\end{array}\right]
\end{equation}
\tikz[overlay,remember picture] {
  \draw[<-,>=stealth] (enter) -- ++(0,-1cm) node [label={[xshift=-8pt,yshift=-20pt]entering}] {};
  \draw[<-,>=stealth] (leaving) -- ++(0,-1cm) node[label={[xshift=8pt,yshift=-20pt]leaving}] {};
}
\end{document}

enter image description here

If you load also xcolor and colortbl, you can change the tint of the rules:

\documentclass{article}
\usepackage{mathtools,xcolor,colortbl}
\usepackage{tikz}
\usetikzlibrary{arrows,shapes,matrix,positioning}
\newcommand{\tikzmark}[2]{\tikz[overlay, remember picture] \node[inner sep=0pt, outer sep=3pt, anchor=base] (#1) {#2};}

\begin{document}
\begin{equation}
\arrayrulecolor{black!30}
\left[
\begin{array}{@{\qquad}|c|@{\quad}|c|@{\qquad}}
           & 0      \\
           & 0      \\
           & \cdots \\
           & \cdots \\ \hline
a^{*}_{ts} & 1      \\ \hline
           & 0      \\
           & \cdots \\
           & \cdots \\
           & \cdots \\
           & 0      \\
           & 0      \\ \hline
\tikzmark{enter}{$c^{*}_s$} & \tikzmark{leaving}{$c^{*}_t$}
\end{array}
\right]
=
\left[\begin{array}{@{}c@{}}
\\ \\ \\ \\
b^{*}_t \\
\\ \\ \\ \\ \\ \\
-v
\end{array}\right]
\arrayrulecolor{black}
\end{equation}
\tikz[overlay,remember picture] {
  \draw[<-,>=stealth] (enter) -- ++(0,-1cm) node [label={[xshift=-8pt,yshift=-20pt]entering}] {};
  \draw[<-,>=stealth] (leaving) -- ++(0,-1cm) node[label={[xshift=8pt,yshift=-20pt]leaving}] {};
}
\end{document}

enter image description here

The color must be reestablished at the end, because \arrayrulecolor is a global declaration.

share|improve this answer
    
awesome! any way to pack the \cdots little tighter? –  Jindan Zhou Jun 4 at 22:28
    
@JindanZhou \newcommand{\pdots}{{\cdot}{\cdot}{\cdot}} –  egreg Jun 4 at 22:35

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.