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

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

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!!!

-
If there is no dotted lines but only dashed lines, then that is still fine as long as you can offer comments how the problem 2. can be resolved. –  Idear Apr 14 at 23:26

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}


-
Gonzalo, +1, I am betting that your method works. Please let me try. –  Idear Apr 15 at 1:19
i like this, but the vertical line seems a bit long both above and below (relative to the size of the parentheses), and the two expressions at the top have different baselines. ??? –  barbara beeton Apr 15 at 6:36
@barbarabeeton Thanks. I fixed the issues with the parentheses and the dotted lines and with the base lines. –  Gonzalo Medina Apr 15 at 14:01
@Idear I'd suggest you to edit your question and add there the information about the document class you are using (revtex4) so it becomes clear for everyone what the problem is with trying to use arydshln. –  Gonzalo Medina Apr 15 at 14:31

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

\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.

-
Your answer is nice, I like it very much. I just find that the incompatibility is due to the documentclass, where mine case is \documentclass[aps,prl,twocolumn,nofootinbib,superscriptaddress,floatfix]{revtex‌​4}; but yours is \documentclass{article}. Do you know why my \documentclass[aps,prl,twocolumn,nofootinbib,superscriptaddress,floatfix]{revtex‌​4} is not compatible with the \usepackage{arydshln,leftidx,mathtools}? –  Idear Apr 15 at 0:00
@Idear: This is why you should always post a minimal working example (MWE). Not sometimes, but always. Why use revtex4 and not revtex4-1? –  Werner Apr 15 at 0:09

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
\strutshortanchors{F}\def\stackalignment{r}\setstackgap{S}{5pt} \stackanchor[15pt]{{}^r}{{}_{m-r}} \def\stackalignment{c} \stackon[1pt]{ \left(\raisebox{2pt}{% \savestack{\num}{~B~\,}\tmplen=\wd\numcontent\relax% \stackunder{\stackon{\dashline{\tmplen}}{\num}}{D\;}% \rotatebox{90}{\kern-1.1\baselineskip\dashline{2.5\baselineskip}}% \savestack{\num}{\,~C~}\tmplen=\wd\numcontent\relax% \stackunder{\stackon{\dashline{\tmplen}}{\num}}{\,E}}% \right) }{% ~~{}_r~\,~_{n-r}% }