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

share|improve this question
2  
As for the matrix brackets, you may simply modify the left and right delimiter to [. –  kan Apr 10 '13 at 21:00
    
@kan The program does not compile if I change the brackets to [ –  TyranaSaur Apr 10 '13 at 21:04
    
I am just writing an answer. I realised I messed that up, I am sorry! –  kan Apr 10 '13 at 21:05
    
To use brackets you need to wrap them in braces:, see Using brackets as delimiters for matrix in TikZ-PGF Matrix Library/ –  Torbjørn T. Apr 10 '13 at 21:06
1  
@MartinSchröder ... thank you? ;-) –  TyranaSaur Apr 11 '13 at 14:22
show 6 more comments

1 Answer

up vote 6 down vote accepted

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.

share|improve this answer
    
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!! –  TyranaSaur 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: 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. –  TyranaSaur 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
show 1 more 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.