9

Can you help me how to do that dashed line on this matrix ?

Can you help me how to do that dashed line on this matrix

AboAmmar
  • 46,352
  • 4
  • 58
  • 127
Sevdije
  • 139

3 Answers3

9

Try

\documentclass{article}
\usepackage{amsmath}
\usepackage{arydshln}
\begin{document}
\begin{equation}
\left[
    \begin{array}{c;{2pt/2pt}c}
        -2 & -4 \\
         2 & -1 \\
        -8 & 16
    \end{array}
\right]
\end{equation}
\end{document}

To obtain

enter image description here

Denis
  • 5,267
  • Unfortunately, it does not work for me; it (TeXStudio) says: Package array Error: Illegal pream-token (;): c' used. \begin{array}{c;{2pt/2pt}c} Package array Error: Illegal pream-token (2pt/2pt):c' used. \begin{array}{c;{2pt/2pt}c} – Alex Konnen Dec 13 '19 at 19:04
  • 1
    @AlexKonnen works fine here. add a MWE and I'll try to see what happens. – Denis Dec 18 '19 at 07:34
  • 1
    I have found the reason why it did not work: my document included \usepackage{tabularx}; I assume that \usepackage{arydshln} is somehow incompatible with the latter; if I remove tabularx, the code works, with tabularx it does not. – Alex Konnen Dec 19 '19 at 19:38
  • The vertical dashes seem to end with a short bold dash. Can this be avoided? – Simd Jul 24 '20 at 08:24
  • You can try to modify the option of the dashed line. Here I set 2pt / 2pt. – Denis Jul 24 '20 at 10:06
6

I will add another simple solution if you like.

enter image description here

\documentclass{article}
\usepackage{arydshln}
\usepackage{mathtools}
\begin{document}
\[ \left[
\begin{array}{c:c}
1 &  2 \\ 
3 & 4 \\
5 & 6 \\ 
\end{array} \right] \]
\end{document}

ADDENDUM: 2020-7-24. Using {bNiceArray} of nicematrix package you will have the square brackets at the same position as in {bmatrix} of amsmath.

\documentclass[a4paper,12pt]{article}

\usepackage{nicematrix} \usepackage{arydshln}

\NiceMatrixOptions{letter-for-dotted-lines=V}

\begin{document} $\begin{bNiceArray}{c:c} 1 & 2 \ 3 & 4 \ 5 & 6 \end{bNiceArray}$ \end{document}

Remark: If you don't put \NiceMatrixOptions{letter-for-dotted-lines=V}, you will have a dotted line (drawn by nicematrix).

Result of the second code

F. Pantigny
  • 40,250
Sebastiano
  • 54,118
  • The dashes are of different lengths which is more or less inevitable if you have long dashes. Is it possible to make them shorter and more tightly packed? – Simd Jul 24 '20 at 08:22
  • Instead of \left[\begin{NiceArray}...\end{NiceArray}\right], it's possible to use \begin{bNiceArray}...\end{bNiceArray} with the same result (which is a result similar to {bmatrix} of amsmath). – F. Pantigny Jul 24 '20 at 08:48
  • @F.Pantigny Very kind F. Pantigny you are right totally. The reason of my addendum is the same: I'm using https://www.papeeria.com/ that can compile with your previous version of nicematrix(I use the most recent TeXlive2019). Please, can you edit my addenudum adding your screenshot? Thank you very much. – Sebastiano Jul 24 '20 at 11:55
  • 1
    @Sebastiano: I have edited your addendum :-) – F. Pantigny Jul 24 '20 at 12:38
  • @F.Pantigny Excellent. Always thank you. – Sebastiano Jul 24 '20 at 12:42
1

In the environments of nicematrix (eg {bNiceArray}), the specifier | in the preamble has an optional argument between square brackets. In this argument, it's possible to specify the TikZ characteristics you wish for your rule.

\documentclass{article}
\usepackage{nicematrix}
\usepackage{tikz}

\begin{document}

$\begin{bNiceArray}{c|[tikz=densely dashed]c} -2 & -4 \ 2 & -1 \ -8 & 16 \ \end{bNiceArray}$

\end{document}

Output of the first code

In this case, the better will probably be better with a dash phase.

\documentclass{article}
\usepackage{nicematrix}
\usepackage{tikz}

\begin{document}

$\begin{bNiceArray}{c|[tikz={densely dashed,dash phase=3pt}]c} -2 & -4 \ 2 & -1 \ -8 & 16 \ \end{bNiceArray}$

\end{document}

Output of the second code

F. Pantigny
  • 40,250