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.

Is there a way to draw a continuous zigzag diagonal better than this one ?

enter image description here

my code :

\documentclass[]{standalone}
\usepackage{tikz}
\usetikzlibrary{matrix}
\usepackage{fullpage,amsmath}
\usepackage{times}
\begin{document}

\begin{tikzpicture}[baseline=(A.center)]
  \tikzset{BarreStyle/.style =   {opacity=.3,line width=3 mm,line cap=round,color=#1}}


\matrix(A) [matrix of math nodes, left delimiter  = {[}, right delimiter ={]}] 
{ M_{11} &|[color = blue]|  M_{12} & M_{13} &|[color = magenta]| M_{14} & M_{15} &|[color = red]| M_{16} \\
  |[color = blue]|M_{21} & M_{22} & |[color = magenta]|M_{23} & M_{24} & |[color = red]|M_{25} & M_{26} \\
  M_{31} & |[color = magenta]|M_{32} & M_{33} &|[color = red]| M_{34} & M_{35} &|[color = orange]| M_{36} \\
  |[color = magenta]| M_{41} & M_{42} &|[color = red]| M_{43} & M_{44} &|[color = orange]| M_{45} & M_{46} \\
  M_{51} & |[color = red]|M_{52} & M_{53} & |[color = orange]|M_{54} & M_{55} &|[color = olive]| M_{56} \\
 |[color = red]|M_{61} & M_{62} &|[color = orange]| M_{63} & M_{64} &|[color = olive]| M_{65} & M_{66} \\
};

 \draw [BarreStyle=red] (A-1-1.west) to (A-1-2.east);
 \draw [BarreStyle=red] (A-1-2.north) to (A-2-2.south);
 \draw [BarreStyle=red] (A-2-2.west) to (A-2-3.east);
 \draw [BarreStyle=red] (A-2-3.north) to (A-3-3.south);
 \draw [BarreStyle=red] (A-3-3.west) to (A-3-4.east);
 \draw [BarreStyle=red] (A-3-4.north) to (A-4-4.south);
 \draw [BarreStyle=red] (A-4-4.west) to (A-4-5.east);
 \draw [BarreStyle=red] (A-4-5.north) to (A-5-5.south);
 \draw [BarreStyle=red] (A-5-5.west) to (A-5-6.east);
 \draw [BarreStyle=red] (A-5-6.north) to (A-6-6.south);

\end{tikzpicture}

\end{document}
share|improve this question
add comment

2 Answers 2

up vote 20 down vote accepted

Possibly...

\documentclass[]{standalone}
\usepackage{tikz}
\usetikzlibrary{matrix}
\usepackage{fullpage,amsmath}
\usepackage{times}
\begin{document}

\begin{tikzpicture}[baseline=(A.center)]
  \tikzset{BarreStyle/.style =   {opacity=.3,line width=3 mm,line cap=round,color=#1}}


\matrix(A) [matrix of math nodes, left delimiter  = {[}, right delimiter ={]}] 
{ M_{11} &|[color = blue]|  M_{12} & M_{13} &|[color = magenta]| M_{14} & M_{15} &|[color = red]| M_{16} \\
  |[color = blue]|M_{21} & M_{22} & |[color = magenta]|M_{23} & M_{24} & |[color = red]|M_{25} & M_{26} \\
  M_{31} & |[color = magenta]|M_{32} & M_{33} &|[color = red]| M_{34} & M_{35} &|[color = orange]| M_{36} \\
  |[color = magenta]| M_{41} & M_{42} &|[color = red]| M_{43} & M_{44} &|[color = orange]| M_{45} & M_{46} \\
  M_{51} & |[color = red]|M_{52} & M_{53} & |[color = orange]|M_{54} & M_{55} &|[color = olive]| M_{56} \\
 |[color = red]|M_{61} & M_{62} &|[color = orange]| M_{63} & M_{64} &|[color = olive]| M_{65} & M_{66} \\
};

 \path [fill=red, fill opacity=0.25,rounded corners=0.125cm]
  (A-1-1.north west) \foreach \i in {1,...,6}{ |- (A-\i-\i.south east) } 
  \foreach \i in {5,...,1} { |- (A-\i-\i.north east) } -- cycle;

\end{tikzpicture}

\end{document}

enter image description here

share|improve this answer
    
This answer is nice too, powerful with the loop, thank you –  Thomas Dec 17 '13 at 11:10
add comment

What about this?

Result

Code (only the changed parts):

\tikzset{BarreStyle/.style = {
    opacity=.3,line width=6 mm,
    line cap=round, line join=round, 
    color=#1, shorten >= -0.1ex, shorten <= -1ex}
}

[Same matrix definition]

\draw [BarreStyle=red] (A-1-1.center) to (A-1-2.center)
                                      to (A-2-2.center)
                                      to (A-2-3.center)
                                      to (A-3-3.center)
                                      to (A-3-4.center)
                                      to (A-4-4.center)
                                      to (A-4-5.center)
                                      to (A-5-5.center)
                                      to (A-5-6.center)
                                      to (A-6-6.center);
share|improve this answer
    
That's perfect. I forgot the .center command ... –  Thomas Dec 17 '13 at 10:42
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.