11

I need a vertically dashed line in my matrix, but my current solution looks like the dashes are going out of the array environment (and they are - i checked in photoshop). Can I manually shorten it by say 1 mm or 0.5 mm?

Here is MWE:

\documentclass[a4paper]{article}
\usepackage{amsmath}
\usepackage{arydshln}
\usepackage{mathtools}
\begin{document}

\begin{equation*}
\setlength{\dashlinegap}{2pt}
\left[\begin{array}{cccc:c}
a_{11} & a_{12} & \cdots & a_{1n} & b_1 \\
a_{21} & a_{22} & \cdots & a_{2n} & b_2 \\
\vdots & \vdots & \ddots & \vdots & \vdots \\
a_{n1} & a_{n2} & \cdots & a_{nn} & b_n
\end{array}
\right]
\end{equation*}

\end{document}

enter image description here

3 Answers 3

7

It seems to me that you are typesetting matrices here. Note that amsmath provides matrix environments (matrix, pmatrix, bmatrix, etc…), so that you do not need to type your own delimiters around an array. (You would want bmatrix.)

To get augmented matrices, use the code from the question: How does this macro for augmented matrices work?


Edit: Included the code for convenience.

\usepackage{arydshln}
\makeatletter
  \renewcommand*\env@matrix[1][*\c@MaxMatrixCols c]{%
    \hskip -\arraycolsep
    \let\@ifnextchar\new@ifnextchar
  \array{#1}}
\makeatother

Put the code in the preamble.


You can then use the same syntax as for arrays, but would end up with the code:

\begin{equation*}
\begin{bmatrix}[cccc:c]
a_{11} & a_{12} & \cdots & a_{1n} & b_1 \\
a_{21} & a_{22} & \cdots & a_{2n} & b_2 \\
\vdots & \vdots & \ddots & \vdots & \vdots \\
a_{n1} & a_{n2} & \cdots & a_{nn} & b_n
\end{bmatrix}
\end{equation*}

Edit 2: Another interesting link: http://texblog.net/latex-archive/maths/amsmath-matrix/

2
  • This is also good, but the first solution is kinda easier, no need for renewing stuff (which I was never really good at xD). But thanks for the suggestion :)
    – dingo_d
    May 24, 2013 at 17:55
  • I agree with you. Note however that this is more in line with tex.stackexchange.com/questions/29840/consistent-typography
    – jmc
    May 24, 2013 at 17:59
7

One possibility, is to tackle the problem in the other sense: instead of shortening the dashed line, you can enlarge the delimiters:

\documentclass[a4paper]{article}
\usepackage{arydshln}
\usepackage{mathtools}

\begin{document}

\begin{equation*}
\delimitershortfall=0pt
\setlength{\dashlinegap}{2pt}
\left[\begin{array}{cccc:c}
a_{11} & a_{12} & \cdots & a_{1n} & b_1 \\
a_{21} & a_{22} & \cdots & a_{2n} & b_2 \\
\vdots & \vdots & \ddots & \vdots & \vdots \\
a_{n1} & a_{n2} & \cdots & a_{nn} & b_n
\end{array}
\right]
\end{equation*}

\end{document}

enter image description here

And, of course, there's the (overkill?) solution using \tikzmark; this gives you more control for fine tuning:

\documentclass[a4paper]{article}
\usepackage{tikz}
\usepackage{mathtools}

\newcommand\tikzmark[1]{%
  \tikz[remember picture,overlay]\coordinate (#1);}

\begin{document}

\begin{equation*}
\left[\begin{array}{ccccc}
a_{11} & a_{12} & \cdots & a_{1n}\hfill\tikzmark{a} & b_1 \\
a_{21} & a_{22} & \cdots & a_{2n} & b_2 \\
\vdots & \vdots & \ddots & \vdots & \vdots \\
a_{n1} & a_{n2} & \cdots & a_{nn}\hfill\tikzmark{b} & b_n
\end{array}
\right]
\end{equation*}

\tikz[remember picture,overlay]
  \draw[dashed,dash pattern={on 4pt off 2pt}] ([xshift=0.5\tabcolsep,yshift=7pt]a.north) -- ([xshift=0.5\tabcolsep,yshift=-2pt]b.south);

\end{document}

enter image description here

4

Here is what you can do with {bNiceMatrix} of nicematrix.

This environment is similar of the classical environment {bmatrix} of amsmath but creates PGF/Tikz under the cells, rows and columns.

It's possible to use that nodes to draw whatever rule you want after the creation of the matrix.

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

\begin{document}

$\begin{bNiceMatrix}
a_{11}  & a_{12} & \cdots & a_{1n} & b_1 \\
a_{21}  & a_{22} & \cdots & a_{2n} & b_2 \\
\vdots & \vdots & \ddots & \vdots & \vdots \\
a_{n1}  & a_{n2} & \cdots & a_{nn} & b_n
\CodeAfter 
  \tikz \draw [dashed,shorten > = 2pt, shorten < = 2pt] (1-|5) -- (last-|5) ;
\end{bNiceMatrix}$

\end{document}

You need several compilations (because nicematrix uses PGF/tikz nodes).

Output of the above code

You must log in to answer this question.

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