Graphics, Figures & TablesDraw line in a Matrix Equation

Information and discussion about graphics, figures & tables in LaTeX documents.
wolfrain
Posts: 20
Joined: Wed Aug 25, 2010 2:42 am

Draw line in a Matrix Equation

Post by wolfrain »

Hey,

sorry to bother you guys, but I think I couldn't find any answers to my specific question after I did some search around the BBS.

Basically, what I want to do is simply draw a diagonal line in my equation, which is shown here.
Drawing1.png
Drawing1.png (44.45 KiB) Viewed 7501 times
I tried to put the environment 'equation' in environment 'figure', but it doesn't work.

Any idea of how to do that??

Many thanks!
Wolfrain

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

achim
Posts: 49
Joined: Wed Aug 05, 2009 2:29 pm

Draw line in a Matrix Equation

Post by achim »

Can you provide a working minimal example for the equation without the line?

I would use pstricks nodes for such a problem as in:
PsEqNode.png
PsEqNode.png (79.17 KiB) Viewed 7497 times
OS: Kubuntu
Distribution: TexLive
Editor: Kile
wolfrain
Posts: 20
Joined: Wed Aug 25, 2010 2:42 am

Draw line in a Matrix Equation

Post by wolfrain »

achim wrote:Can you provide a working minimal example for the equation without the line?

I would use pstricks nodes for such a problem as in:
PsEqNode.png

Thank you my friend!!

Code: Select all

\documentclass[10pt,a4paper]{scrartcl}
\usepackage{amsmath}

\begin{document}
    
\begin{eqnarray}
	\left | A_{4 \times 4} \right |=
	\begin{vmatrix}
		a_{11} & a_{12} & a_{13} & a_{14}\\ 
		a_{21} & a_{22} & a_{23} & a_{24}\\ 
		a_{31} & a_{32} & a_{33} & a_{34}\\ 
		a_{41} & a_{42} & a_{43} & a_{44}
	\end{vmatrix}
 		& = & ~~~a_{11} 
	\begin{vmatrix}
		a_{22} & a_{23} & a_{24}\\ 
		a_{32} & a_{33} & a_{34}\\ 
		a_{42} & a_{43} & a_{44}
	\end{vmatrix}
		-a_{12}
	\begin{vmatrix}
		a_{21} & a_{23} & a_{24}\\ 
		a_{31} & a_{33} & a_{34}\\ 
		a_{41} & a_{43} & a_{44}
	\end{vmatrix}		\nonumber	\\
		&		& + \: a_{13}
	\begin{vmatrix}
		a_{21} & a_{22} & a_{24}\\ 
		a_{31} & a_{32} & a_{34}\\ 
		a_{41} & a_{42} & a_{44}
	\end{vmatrix}
		-a_{14}
	\begin{vmatrix}
		a_{21} & a_{22} & a_{23}\\ 
		a_{31} & a_{32} & a_{33}\\ 
		a_{41} & a_{42} & a_{43}
	\end{vmatrix}  	\nonumber	\\
	%\IEEEyesnumber\\
	%%%%%%%%%%%%%%%%%%%%%
		& = & ~~a_{11}
	\left \{ a_{22}\underline{\begin{vmatrix}
		a_{33} & a_{34} \\ 
		a_{43} & a_{44} 
	\end{vmatrix}  }_{<1>}
	%{\tikz \node[draw,circle]{12};}
		-a_{23}\underline{\begin{vmatrix}
		a_{32} & a_{34} \\ 
		a_{42} & a_{44} 
	\end{vmatrix}}_{<2>}
		+a_{24}\underline{\begin{vmatrix}
		a_{32} & a_{33} \\ 
		a_{42} & a_{43} 
	\end{vmatrix} }_{<3>}
	\right \}	\nonumber	\\
		&		& -a_{12}
	\left \{ a_{21}\underline{\begin{vmatrix}
		a_{33} & a_{34} \\ 
		a_{43} & a_{44} 
	\end{vmatrix}}_{<1>}  
		-a_{23}\underline{\begin{vmatrix}
		a_{31} & a_{34} \\ 
		a_{41} & a_{44} 
	\end{vmatrix}}_{<4>}
		+a_{24}\underline{\begin{vmatrix}
		a_{31} & a_{33} \\ 
		a_{41} & a_{43} 
	\end{vmatrix} }_{<5>}
	\right \}	\nonumber	\\
		&		& +a_{13}
	\left \{ a_{21}\underline{\begin{vmatrix}
		a_{32} & a_{34} \\ 
		a_{42} & a_{44} 
	\end{vmatrix}  }_{<2>}
		-a_{22}\underline{\begin{vmatrix}
		a_{31} & a_{34} \\ 
		a_{41} & a_{44} 
	\end{vmatrix}}_{<4>}
		+a_{24}\underline{\begin{vmatrix}
		a_{31} & a_{32} \\ 
		a_{41} & a_{42} 
	\end{vmatrix} }_{<6>}
	\right \}	\nonumber	\\
		&		& -a_{14}
	\left \{ a_{21}\underline{\begin{vmatrix}
		a_{32} & a_{33} \\ 
		a_{42} & a_{43} 
	\end{vmatrix}  }_{<3>}
		-a_{22}\underline{\begin{vmatrix}
		a_{31} & a_{33} \\ 
		a_{41} & a_{43} 
	\end{vmatrix}}_{<5>}
		+a_{23}\underline{\begin{vmatrix}
		a_{31} & a_{32} \\ 
		a_{41} & a_{42} 
	\end{vmatrix} }_{<6>}
	\right \}
	%\IEEEyesnumber\\
	\label{eq:4-dimension-to-2-dimension}
	\end{eqnarray}	
	
	\end{document}
Above is the original code I used to generate the equation.
Actually the .png file you attached is really close to what I want! Apart from the red line, I am also trying to add some curly lines, just like what you did, in my equation.

Really thank you for your assistance!
wolfrain
achim
Posts: 49
Joined: Wed Aug 05, 2009 2:29 pm

Draw line in a Matrix Equation

Post by achim »

Code: Select all

\documentclass[10pt,a4paper]{scrartcl}
\usepackage{amsmath}


\usepackage{pstricks}
\usepackage{pst-all}
\usepackage{pstricks-add}

\begin{document}
	
\begin{eqnarray}
	\left | A_{4 \times 4} \right |=
	\begin{vmatrix}
		a_{11} & a_{12} & a_{13} & a_{14}\\
		a_{21} & a_{22} & a_{23} & a_{24}\\
		a_{31} & a_{32} & \rnode{a33a}{a_{33}} & a_{34}\\
		a_{41} & a_{42} & a_{43} & a_{44}
	\end{vmatrix}
		& = & ~~~a_{11}
	\begin{vmatrix}
		a_{22} & a_{23} & a_{24}\\
		a_{32} & \rnode{a33b}{a_{33}} & a_{34}\\
		a_{42} & a_{43} & a_{44}
	\end{vmatrix}
		-a_{12}
	\begin{vmatrix}
		a_{21} & a_{23} & a_{24}\\
		a_{31} & a_{33} & a_{34}\\
		a_{41} & a_{43} & a_{44}
	\end{vmatrix}      \nonumber   \\
		&      & + \: a_{13}
	\begin{vmatrix}
		a_{21} & a_{22} & a_{24}\\
		a_{31} & a_{32} & a_{34}\\
		a_{41} & a_{42} & a_{44}
	\end{vmatrix}
		-a_{14}
	\begin{vmatrix}
		a_{21} & a_{22} & a_{23}\\
		a_{31} & a_{32} & a_{33}\\
		a_{41} & a_{42} & a_{43}
	\end{vmatrix}     \nonumber   \\
	%\IEEEyesnumber\\
	%%%%%%%%%%%%%%%%%%%%%
		& = & ~~a_{11}
	\rnode{leftbracket}{}\left \{ a_{22}\underline{\begin{vmatrix}
		a_{33} & a_{34} \\
		a_{43} & a_{44}
	\end{vmatrix}  }_{<1>}
		-a_{23}\underline{\begin{vmatrix}
		a_{32} & a_{34} \\
		a_{42} & a_{44}
	\end{vmatrix}}_{<2>}
		+a_{24}\underline{\begin{vmatrix}
		a_{32} & a_{33} \\
		a_{42} & a_{43}
	\end{vmatrix} }_{<3>}
	\right \}   \nonumber   \\
		&      & -a_{12}
	\left \{ a_{21}\underline{\begin{vmatrix}
		a_{33} & a_{34} \\
		a_{43} & a_{44}
	\end{vmatrix}}_{<1>} 
		-a_{23}\underline{\begin{vmatrix}
		a_{31} & a_{34} \\
		a_{41} & a_{44}
	\end{vmatrix}}_{<4>}
		+a_{24}\underline{\begin{vmatrix}
		a_{31} & a_{33} \\
		a_{41} & a_{43}
	\end{vmatrix} }_{<5>}
	\right \}   \nonumber   \\
		&      & +a_{13}
	\left \{ a_{21}\underline{\begin{vmatrix}
		a_{32} & a_{34} \\
		a_{42} & a_{44}
	\end{vmatrix}  }_{<2>}
		-a_{22}\underline{\begin{vmatrix}
		a_{31} & a_{34} \\
		a_{41} & a_{44}
	\end{vmatrix}}_{<4>}
		+a_{24}\underline{\begin{vmatrix}
		a_{31} & a_{32} \\
		a_{41} & a_{42}
	\end{vmatrix} }_{<6>}
	\right \}   \nonumber   \\
		&      & -a_{14}
	\left \{ a_{21}\underline{\begin{vmatrix}
		a_{32} & a_{33} \\
		a_{42} & a_{43}
	\end{vmatrix}  }_{<3>}
		-a_{22}\underline{\begin{vmatrix}
		a_{31} & a_{33} \\
		a_{41} & a_{43}
	\end{vmatrix}}_{<5>}
		+a_{23}\underline{\begin{vmatrix}
		a_{31} & a_{32} \\
		a_{41} & a_{42}
	\end{vmatrix} }_{<6>}
	\right \}\rnode{rightbracket}{}
	%\IEEEyesnumber\\
	\label{eq:4-dimension-to-2-dimension}
	%
	% Node connections:
	\ncline[linecolor=red]{leftbracket}{rightbracket}
	\nccurve[angleA=-60, ncurvA=1.5, angleB= 125, linewidth=0.6pt, linecolor=gray, linestyle=dashed]{->}{a33a}{a33b}
	\end{eqnarray}   
	
	\end{document}
example.png
example.png (41.67 KiB) Viewed 7496 times
What the code means:
\rnode{label}{something} places a node on the 'something' object with a given label (much like labels for references in figures and tables).
You can then connect any existing node by using \ncline{firstlabel}{secondlabel} for a straight line. Additional commands for changing the line stile are accepted too. The \nccurve command does the same but with a curve instead of a plain straight line.
There are much more connecting lines available to choose from. For more on this check the pstricks documentation

Note:
The pstricks packages loaded in the preamble. Pdflatex compilation will nolonger work with the pdf package. You will have to compile tex-dvi-ps-pdf in order to use pstricks. This also means that any graphics included in the document (by \includegraphics{myepspic}) need to be encapsulated post script figures.
I hope this is not too much of a trade off for you. I personally use pstricks a lot and hence always compile tex-dvi-ps-pdf.

The last closing curly bracket looks odd, I don't know where this is coming from...(?) But, it was there before I started adding the nodes and lines. I'm clueless as to what causes this.

Cheers
Achim

ps: A general note on lines in equations. I think it's not regarded as good practice to cross out terms in equations, this should probably rather be described in text form. Also It becomes kind of messed up if you have too many arrows and lines pointing form one term to an other. I know this is exactly what I've done in the example I showed in my first response. I should mention, however, that I used this matrix in a beamer presentation and it served well for visualising my point.
"Use the Force wisely, Anakin... :-) "
OS: Kubuntu
Distribution: TexLive
Editor: Kile
achim
Posts: 49
Joined: Wed Aug 05, 2009 2:29 pm

Re: Draw line in a Matrix Equation

Post by achim »

pps: The weird looking thing on the last bracket is the equation number.
If you put a \nonumber after the bracket it disappears...

Try to decrease the width of the equation or decrease the left/right borders of the document.
OS: Kubuntu
Distribution: TexLive
Editor: Kile
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Draw line in a Matrix Equation

Post by localghost »

wolfrain wrote:[…] Above is the original code I used to generate the equation. […]
It is not recommendable to use the eqnarray environment [1]. Include the amsmath package and use its align environment. For more useful stuff about math typesetting take a look at the »Math mode« document.

[1] The PracTeX Journal — TeX Users Group, Lars Madsen: Avoid eqnarray!


Thorsten
wolfrain
Posts: 20
Joined: Wed Aug 25, 2010 2:42 am

Draw line in a Matrix Equation

Post by wolfrain »

achim wrote:pps: The weird looking thing on the last bracket is the equation number.
If you put a \nonumber after the bracket it disappears...

Try to decrease the width of the equation or decrease the left/right borders of the document.

Thank you so so much for your reply! :D :D

Your method really works in my case, however, there are 8 errors saying that "! No room for a new \dimen .", I think it is caused from the pstricks packages.
CrazyHorse
Posts: 351
Joined: Sat Aug 02, 2008 8:47 am

Draw line in a Matrix Equation

Post by CrazyHorse »

wolfrain wrote:
achim wrote:Your method really works in my case, however, there are 8 errors saying that "! No room for a new \dimen .", I think it is caused from the pstricks packages.

Code: Select all

\usepackage{etex}
HErbert
wolfrain
Posts: 20
Joined: Wed Aug 25, 2010 2:42 am

Draw line in a Matrix Equation

Post by wolfrain »

localghost wrote:
wolfrain wrote:[…] Above is the original code I used to generate the equation. […]
It is not recommendable to use the eqnarray environment [1]. Include the amsmath package and use its align environment. For more useful stuff about math typesetting take a look at the »Math mode« document.

As soon as the problem is sorted out, please act exactly according to Section 3 of the Board Rules.

[1] The PracTeX Journal — TeX Users Group, Lars Madsen: Avoid eqnarray!


Best regards
Thorsten


Thank you for your advice mate! I will give it a try. 8-)
wolfrain
Posts: 20
Joined: Wed Aug 25, 2010 2:42 am

Draw line in a Matrix Equation

Post by wolfrain »

CrazyHorse wrote:
wolfrain wrote:
achim wrote:Your method really works in my case, however, there are 8 errors saying that "! No room for a new \dimen .", I think it is caused from the pstricks packages.

Code: Select all

\usepackage{etex}
HErbert
Thank you for your reply~

Actually the error message is something like this

Code: Select all

! No room for a new \dimen .
\ch@ck ...\else \errmessage {No room for a new #3}
                                                 \fi
1.297 \newdimen\pshooklength
And all 8 errors have different last lines saying:

Code: Select all

1.298  \newdimen\pshookwidth
1.1546 \newdimen\chart@ColorIndex
1.1547 \newdimen\chart@ColorStep
1.1548 \newdimen\pst@chartHeight
1.1549 \newdimen\pst@chartStackDepth
1.1550 \newdimen\pst@chartStackWidth
Unfortunately, it doesn't work even though I include this 'etex' package...
Post Reply