Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

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/

share|improve this answer
    
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 '13 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 '13 at 17:59
add comment

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.