4

So, here is what I want to do: I have created a matrix C and another Matrix D. And I have labelled the columns and rows. Now, I want to join these two matrices together, keeping the labels. But I want - I hope this is posssible - to have a dotted line go through the matrix, indicating where labels 'TX^C' end and where labels 'TX^D' start.

This is what I have so far:

\documentclass[a4paper12pt]{article}
\usepackage{geometry}
\usepackage{blkarray}
\usepackage{amsmath}
\usepackage{xcolor}
\usepackage{graphicx}

\begin{document}

\[\mathbf{J} = 
\begin{blockarray}{cccccc}
RB_1 & RB_2 & RB_3 & \dots & RB_m \\
\begin{block}{(ccccc)c}
1 & 0 & 1 & \dots & 0 & TX_1^C \\
0 & 1 & 0 & \dots & 0 & TX_2^C \\
\vdots & \vdots & \vdots &  & \vdots &  \\
&   &   &  &  &  \\
0 & 0 & 0 & \dots & 1 & TX_{max}^C \\
1 & 0 & 1 & \dots & 0 & TX_1^D \\
0 & 1 & 0 & \dots & 0 & TX_2^D \\
\vdots & \vdots & \vdots &  & \vdots &  \\
&   &   &  &  &  \\
0 & 0 & 0 & \dots & 1 & TX_{max}^D \\
\end{block}
\end{blockarray}
\]

\end{document}

Only the dotted line is missing. Alternatively, shading the background of the upper matrix in a light color would be nice as well. I have just read a similar question here. But since I don't know LaTeX so well, I don't know if I want to overcomplicate things by making use of tikz.

Small Edit: What, if I want two vertical labels? I was trying this, for example:

\[\mathbf{Pairs} = 
\begin{blockarray}{cc}
Transmitter & Receiver \\
\begin{block}{c(cc)c}
TX_1^C & (x,y) & (x,y) & BS   \\
TX_2^C & (x,y) & (x,y) & BS     \\
&\vdots & \vdots  \\
TX_{max}^C & (x,y) & (x,y) & BS  \\
\BAhhline{......} 
TX_1^D & (x,y) & (x,y) &RX_1^D   \\
TX_2^D & (x,y) & (x,y) &RX_2^D   \\
&\vdots & \vdots   \\
TX_{ax}^D & (x,y) & (x,y) &RX_{max}^D  \\
\end{block}
\end{blockarray}
\]

2 Answers 2

3

The package blkarray already offers several commands for different lines. One of them is \BAhhline where you can define the kind of line

\documentclass[a4paper12pt]{article}
\usepackage{geometry}
\usepackage{blkarray}
\usepackage{amsmath}
\usepackage{xcolor}
\usepackage{graphicx}

\begin{document}

\[\mathbf{J} = 
\begin{blockarray}{cccccc}
RB_1 & RB_2 & RB_3 & \dots & RB_m \\
\begin{block}{(ccccc)c}
1 & 0 & 1 & \dots & 0 & TX_1^C \\
0 & 1 & 0 & \dots & 0 & TX_2^C \\
\vdots & \vdots & \vdots &  & \vdots &  \\
&   &   &  &  &  \\
0 & 0 & 0 & \dots & 1 & TX_{max}^C \\
\BAhhline{......}
1 & 0 & 1 & \dots & 0 & TX_1^D \\
0 & 1 & 0 & \dots & 0 & TX_2^D \\
\vdots & \vdots & \vdots &  & \vdots &  \\
&   &   &  &  &  \\
0 & 0 & 0 & \dots & 1 & TX_{max}^D \\
\end{block}
\end{blockarray}
\]

\end{document}

enter image description here

3
  • Thx so much, Ignasi! This is exactly what I want. Just - see my edit - what if I only label the columns and not the rows? It doesn't seem to work the way I am trying to do it. I have included the extra & before the \` , because this is where usually there would be the labels. If I leave the &`, at least I don't get an error. But the left bracket is far to much to the left
    – Luk
    Commented Nov 10, 2018 at 12:39
  • hmm... actually, let me correct this: Can you tell me a way of how to have two vertical labels? One on the right and one on the left ?
    – Luk
    Commented Nov 10, 2018 at 12:48
  • ok, nevermind. I have opened a new question for this. Thx so much for your help, again!
    – Luk
    Commented Nov 10, 2018 at 13:35
0

With {NiceMatrix} of nicematrix, you have keys first-row, last-row, first-col and last-col to specify exterior rows and columns and you can add a dashed rule by using \Hline[tikz=dashed] which draws the rule with TikZ.

\documentclass[a4paper,12pt]{article}
\usepackage{geometry}
\usepackage{nicematrix,tikz}

\begin{document}

\[\mathbf{J} = 
\begin{pNiceMatrix}[first-row,last-col=6]
RB_1 & RB_2 & RB_3 & \dots & RB_m \\
1 & 0 & 1 & \dots & 0 & TX_1^C \\
0 & 1 & 0 & \dots & 0 & TX_2^C \\
\vdots & \vdots & \vdots &  & \vdots &  \\
&   &   &  &  &  \\
0 & 0 & 0 & \dots & 1 & TX_{max}^C \\
\Hline[tikz=dashed]
1 & 0 & 1 & \dots & 0 & TX_1^D \\
0 & 1 & 0 & \dots & 0 & TX_2^D \\
\vdots & \vdots & \vdots &  & \vdots &  \\
&   &   &  &  &  \\
0 & 0 & 0 & \dots & 1 & TX_{max}^D \\
\end{pNiceMatrix}
\]

\end{document}

Output of the first code

By default, the rules are not drawn in the exterior rows and columns. If you want the dashed rule in the last column also, you have to use another technic. Using {NiceArray} and specify the position of the rounded brackets directly in the preamble of that {NiceArray}.

\documentclass[a4paper,12pt]{article}
\usepackage{geometry}
\usepackage{nicematrix,tikz}

\begin{document}

\[\mathbf{J} = 
\begin{NiceArray}{(ccccc)c}[first-row]
RB_1 & RB_2 & RB_3 & \dots & RB_m \\
1 & 0 & 1 & \dots & 0 & TX_1^C \\
0 & 1 & 0 & \dots & 0 & TX_2^C \\
\vdots & \vdots & \vdots &  & \vdots &  \\
&   &   &  &  &  \\
0 & 0 & 0 & \dots & 1 & TX_{max}^C \\
\Hline[tikz=dashed]
1 & 0 & 1 & \dots & 0 & TX_1^D \\
0 & 1 & 0 & \dots & 0 & TX_2^D \\
\vdots & \vdots & \vdots &  & \vdots &  \\
&   &   &  &  &  \\
0 & 0 & 0 & \dots & 1 & TX_{max}^D \\
\end{NiceArray}
\]

\end{document}

Output of the above code

If you want more space on both sides of the dashed, you have to use the key total-width for the command \Hline.

\documentclass[a4paper,12pt]{article}
\usepackage{geometry}
\usepackage{nicematrix,tikz}

\begin{document}

\[\mathbf{J} = 
\begin{NiceArray}{(ccccc)c}[first-row]
RB_1 & RB_2 & RB_3 & \dots & RB_m \\
1 & 0 & 1 & \dots & 0 & TX_1^C \\
0 & 1 & 0 & \dots & 0 & TX_2^C \\
\vdots & \vdots & \vdots &  & \vdots &  \\
&   &   &  &  &  \\
0 & 0 & 0 & \dots & 1 & TX_{max}^C \\
\Hline[tikz=dashed,total-width=2mm]
1 & 0 & 1 & \dots & 0 & TX_1^D \\
0 & 1 & 0 & \dots & 0 & TX_2^D \\
\vdots & \vdots & \vdots &  & \vdots &  \\
&   &   &  &  &  \\
0 & 0 & 0 & \dots & 1 & TX_{max}^D \\
\end{NiceArray}
\]

\end{document}

Output of the above code

The package nicematrix provides also tools to improve the dotted rules.

\documentclass[a4paper,12pt]{article}
\usepackage{geometry}
\usepackage{nicematrix,tikz}

\begin{document}

\NiceMatrixOptions{xdots/shorten=6pt}

\[\mathbf{J} = 
\begin{NiceArray}{(ccccc)c}[first-row,renew-dots]
RB_1 & RB_2 & RB_3 & \dots & RB_m \\
1 & 0 & 1 & \dots & 0 & TX_1^C \\
0 & 1 & 0 & \dots & 0 & TX_2^C \\
\vdots & \vdots & \vdots &  & \vdots &  \\
&   &   &  &  &  \\
0 & 0 & 0 & \dots & 1 & TX_{max}^C \\
\Hline[tikz=dashed,total-width=2mm]
1 & 0 & 1 & \dots & 0 & TX_1^D \\
0 & 1 & 0 & \dots & 0 & TX_2^D \\
\vdots & \vdots & \vdots &  & \vdots &  \\
&   &   &  &  &  \\
0 & 0 & 0 & \dots & 1 & TX_{max}^D \\
\end{NiceArray}
\]

\end{document}

Output of the above code

You must log in to answer this question.

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