4

I have a matrix written as following:

\begin{equation}
 A={
 \begin{pmatrix} 
1 & -1 & 0  & 0 & 0 & \dots\\
0 &  1 & -1 & 0 & 0 &\dots\\ 
1 &  0 & -1 & 0 & 0 &\dots\\
0 &  0 &  1 & -1 & 0 &\dots\\
1 &  0 &  0 & -1 & 0 &\dots\\
0 &  0 &  0 &  1 & -1 &\dots\\
. &  . &  . & . &  . &\dots\\
. &  . &  . & . &  . &\dots\\
\end{pmatrix}
\end{equation}

I would like to have a box which frames the content of the forth column from its forth row to the end. I am wondering how it should be done?! I will appreciate for a help.

1

2 Answers 2

5

Here's one way with using a \smashed \fbox around a dropped \rule. EDITED to provide a colored box.

\documentclass{article}
\usepackage{amsmath,xcolor}
\fboxrule=1pt
\begin{document}
\begin{equation}
 A=
 \begin{pmatrix} 
1 & -1 & 0  & 0 & 0 & \dots\\
0 &  1 & -1 & 0 & 0 &\dots\\ 
1 &  0 & -1 & 0 & 0 &\dots\\
0 &  0 &  1 & \smash{\color{red}\fbox{\color{black}\rule[-50pt]{0pt}{1pt}$-1$}} & 0 &\dots\\
1 &  0 &  0 & -1 & 0 &\dots\\
0 &  0 &  0 &  1 & -1 &\dots\\
. &  . &  . & . &  . &\dots\\
. &  . &  . & . &  . &\dots\\
\end{pmatrix}
\end{equation}
\end{document}

enter image description here

And if you wanted the matrix entries right aligned, you could use a tabstack:

\documentclass{article}
\usepackage{tabstackengine,xcolor}
\def\mykern{\kern-\fboxsep\kern-\fboxrule}
\def\cfbox#1{\mykern\smash{\color{red}\protect\fbox{\color{black}#1}\mykern}}
\fboxrule=1pt
\begin{document}
\begin{equation}
 A=
\setstacktabbedgap{1.5ex}
\renewcommand\stackalignment{r}
 \parenMatrixstack{ 
1 & -1 & 0  & 0 & 0 & \dots\\
0 &  1 & -1 & 0 & 0 &\dots\\ 
1 &  0 & -1 & 0 & 0 &\dots\\
0 &  0 &  1 & \cfbox{\protect\rule[-50pt]{0pt}{1pt}$-1$} & 0 &\dots\\
1 &  0 &  0 & -1 & 0 &\dots\\
0 &  0 &  0 &  1 & -1 &\dots\\
. &  . &  . & . &  . &\dots\\
. &  . &  . & . &  . &\dots
}
\end{equation}
\end{document}

enter image description here

2
  • Thanks! Looks like exactly what I am looking for, but is there any way to change the colour of the box too?
    – Dalek
    Dec 16, 2014 at 2:44
  • @Steven B. Segletes: You also can have a right-aligned matrix with the pmatrix* environment from mathtools.
    – Bernard
    Dec 16, 2014 at 11:07
4

With tikzmark

\documentclass{article}
\usepackage{amsmath,tikz}
\newcommand{\tikzmark}[2]{\tikz[overlay,remember picture] \node[minimum width=1.5em] (#1) {#2};}
\begin{document}
\begin{equation}
 A=
 \begin{pmatrix}
1 & -1 & 0  & 0 & 0 & \dots\\
0 &  1 & -1 & 0 & 0 &\dots\\
1 &  0 & -1 & 0 & 0 &\dots\\
0 &  0 &  1 & \tikzmark{a}{$-1$} & 0 &\dots\\
1 &  0 &  0 & -1 & 0 &\dots\\
0 &  0 &  0 &  1 & -1 &\dots\\
. &  . &  . & . &  . &\dots\\
. &  . &  . & \tikzmark{b}{.} &  . &\dots\\
\end{pmatrix}
\end{equation}
\tikz[overlay,remember picture]\draw[thick,red] (a.north west) rectangle (b.south east);
\end{document}

enter image description here

1
  • I was able to get the correct vertical alignment by adding anchor=base in the node options: tikzmark is then defined as \tikz[overlay,remember picture] \node[anchor=base] (#1) {#2}; (I also removed the minimum width for my purposes)
    – Isaac Ren
    Aug 29, 2022 at 7:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .