6

I am using this solution here to make long dashes within a matrix, and it is working well. The code is:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}

% possible to customize here the dash aspect
\newcommand{\mydash}{
\draw(0.3,0.5ex)--(-0.3,0.5ex);
}

\begin{document}
\[P=
\begin{tikzpicture}[baseline=-0.5ex]
\matrix(m)[matrix of math nodes,left delimiter=(,right delimiter=),ampersand replacement=\&]
{
\mydash \&   y_1 \&   \mydash   \\
\mydash \&   y_2+z_2 \&  \mydash    \\
\mydash \&   y_3 \&   \mydash \\
};
\end{tikzpicture}
\]

\end{document}

However, I am now sure how to start writing full blown equations with it. I have not had much luck. The above makes a nice matrix with lines along the rows.

1) What I want is something like P = X Y Z, where X, Y , and Z, are all shown with the lines along its rows as in the prior example given. I cannot seem to concatenate them for whatever reason though...

2) I would like the matrix brackets to also be square, and not curvy.

Spacey
  • 1,159

1 Answers1

8

1) The point to realise is that: everything is happening in a math mode. And, tikzpicture is is simply a new environment in the math mode. So, you are not writing equations in Tikz. You're using Tikz only to get the dashes right. An example will hopefully set this right for you:

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{matrix}

% possible to customize here the dash aspect
\newcommand{\mydash}{
\draw(0.3,0.5ex)--(-0.3,0.5ex);
}

\begin{document}
\[X=
\begin{tikzpicture}[baseline=-0.5ex]
\matrix(m)[matrix of math nodes,left delimiter={[},right delimiter={]},ampersand replacement=\&]
{
\mydash \&   u_1 \&   \mydash \\
\mydash \&   u_2 \&   \mydash \\
\mydash \&   u_3 \&   \mydash \\
};
\end{tikzpicture}
\begin{tikzpicture}[baseline=-0.5ex]
\matrix(m)[matrix of math nodes,left delimiter={[},right delimiter={]},ampersand replacement=\&]
{
\mydash \&   b_1 \&  \mydash \\
\mydash \&   b_2 \&  \mydash \\
\mydash \&   b_3 \&  \mydash \\
\mydash \&   b_4 \&  \mydash \\
};
\end{tikzpicture}
\begin{bmatrix}
\biggl| \\
c_1 \\
\biggl|
\end{bmatrix}
\]

\end{document}

Output.

Output Image

2) For the second question about the shape of the enclosing braces, we need to appropriately modify the options: left delimiter and right delimiter. In this case, we set it to: {[} and {]} respectively.

Hope that helps.

kan
  • 4,545
  • Very, very, beautiful. Thank you very much. A follow up or two: Would it be hard to make this modification. 2) Suppose on the first matrix, you want to populate it with say, 4 numbers like a normal matrix. Also, modification is straight forward? Thanks!! – Spacey Apr 10 '13 at 21:40
  • @Mohammad (1) It is possible, if you don't insist that the braces are at the same level. (Even otherwise, it should, in principle, be possible, but, I am just not aware of a method.) Check this out: https://www.writelatex.com/138403qnzgnm. – kan Apr 10 '13 at 21:46
  • (2) As I said, you're in a math mode!! So, at the place, where you'd like your matrix, simply \begin{bmatrix} and input your matrix! – kan Apr 10 '13 at 21:47
  • Yes, for (1) I dont insist that they are at the same level. How would you modify that to do so? For (2), thanks - got it. – Spacey Apr 10 '13 at 21:49
  • @Mohammad Oh, since you don't care about the level at which they are placed, the link to writelatex in that comment does what you need! In particular, it uses the construct \underbrace{}_{} from amsmath. So, you'd enclose an entire tikzpicture or bmatrix environment within the first braces and write the text you like underneath that in the second braces. You may please look at the link and ask if you get stuck. :) – kan Apr 10 '13 at 21:55