TransWikia.com

How to create vertical and horizontal dotted lines in a matrix?

TeX - LaTeX Asked by wonderich on December 21, 2020

Similar to this question, I am trying to output a similar matrix with dotted line instead of dashed line.

enter image description here

  1. Is there anyway to do this?

  2. I also try to use these three packages:

    usepackage{tabularx}
    usepackage{longtable}
    usepackage{arydshln}
    
  3. I also like to learn how to implement this in documentclass{revtex4}, in addition to using in documentclass{article}. As far as we know that arydshln may not be compatible with revtex4 or revtex4-1 as far as I tried.

I encounter a problem like this post. And I add arydshln after the tabularx; but it cannot compile successfully, but only output errors. Could someone offer any hints or some resolutions?

The answer needs not to be complete. Thank you for your help!!!

4 Answers

Since revtex4 seems to be incompatible with the arydshln package, here's an option using TikZ:

documentclass[aps,prl,twocolumn,nofootinbib,superscriptaddress,floatfix]{revtex4}
usepackage{tikz}
usetikzlibrary{matrix}

begin{document}

[
Biggl(mkern-5mu
begin{tikzpicture}[baseline=-.65ex]
matrix[
  matrix of math nodes,
  column sep=1ex,
] (m)
{
B & C 
D & E 
};
draw[dotted]
  ([xshift=0.5ex]m-1-1.north east) -- ([xshift=0.5ex]m-2-1.south east);
draw[dotted]
  (m-1-1.south west) -- (m-1-2.south east);
node[above,text depth=1pt] at (m-1-1.north) {$scriptstyle r$};  
node[above,text depth=1pt] at (m-1-2.north) {$scriptstyle n-r$};
node[left,overlay] at ([xshift=-1.2ex]m-1-1.west) {$scriptstyle r$};
node[left,overlay] at ([xshift=-1.2ex]m-2-1.west) {$scriptstyle n-r$};
end{tikzpicture}mkern-5mu
Biggr)
]

end{document}

enter image description here

Correct answer by Gonzalo Medina on December 21, 2020

You can adjust the dash and gap of the hdashline by modifying the lengths dashlinedash and dashlinegap:

enter image description here

documentclass{article}
usepackage{tabularx}
usepackage{arydshln,leftidx,mathtools}

setlength{dashlinedash}{.4pt}
setlength{dashlinegap}{.8pt}

begin{document}
[
  leftidx{_{m-r}^{phantom{m-r}llap{$scriptstyle r$}}}{left( begin{array}{c:c}
    smash{overset{r}{B}} & mathclap{smash{overset{n-r}{C}}} 
    hdashline
    D & E
  end{array} right)}{}
]

noindent
begin{tabularx}{linewidth}{X:X}
  hdashline
  ABC & DEF 
  hdashline
end{tabularx}
end{document}

The default for both of the lengths is 4pt.

Answered by Werner on December 21, 2020

This uses a stacking approach. This answer is helping me to think of ways to automate dotted/dashed lines as part of stacks, which in this MWE, had to be done very manually.

documentclass{article}
usepackage[usestackEOL]{stackengine}
usepackage{graphicx}
stackMath
% DASHED LINE OF SPECIFIED LENGTH
% From morsburg at http://tex.stackexchange.com/questions/12537/
% how-can-i-make-a-horizontal-dashed-line/12553#12553
defdashfill{cleadershbox to .5em{rule{.4ex}{.4pt}}hfill}
newcommanddashline[1]{hbox to #1{dashfillhfil}}
newlengthtmplen
begin{document}
[
strutshortanchors{F}defstackalignment{r}setstackgap{S}{5pt}
stackanchor[15pt]{{}^r}{{}_{m-r}}
defstackalignment{c}
stackon[1pt]{
  left(raisebox{2pt}{%
  savestack{num}{$~B~,$}tmplen=wdnumcontentrelax%
  stackunder{stackon{dashline{tmplen}}{num}}{D;}%
  rotatebox{90}{kern-1.1baselineskipdashline{2.5baselineskip}}%
  savestack{num}{$,~C~$}tmplen=wdnumcontentrelax%
  stackunder{stackon{dashline{tmplen}}{num}}{,E}}%
  right)
}{%
  ~~{}_r~,~_{n-r}%
}
]
end{document}

enter image description here

Answered by Steven B. Segletes on December 21, 2020

The package nicematrix has features to that directly.

documentclass{article}
usepackage{nicematrix}

begin{document}

NiceMatrixOptions{code-for-first-row = scriptstyle,code-for-first-col = scriptstyle }

$A = begin{pNiceArray}{c:c}[first-row, first-col, columns-width=auto]
    & r & n-r 
r   & B & C 
hdottedline
m-r & D & E 
end{pNiceArray}$

end{document}

Output of the above code

Answered by F. Pantigny on December 21, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP