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.
\documentclass{standalone}
\usepackage{comment}

\usepackage{tikz,pgf}

\usetikzlibrary{fit,scopes,calc,matrix,positioning,decorations.pathmorphing}

\begin{document}

\begin{tikzpicture}
    \begin{scope}
            \matrix (A5) [matrix of nodes, ampersand replacement = \&] {
                {7}  \& {2} \& {7} \& {7} \& {2} \& {8}\\
            };
    \end{scope}
    \begin{scope}
        \matrix (B5) at ([yshift=-2.5cm]A5-1-1.south) [anchor=B5-1-1.north, matrix of nodes, ampersand replacement = \&] {
            {12} \& {7} \& {2} \& {7} \& {2} \& {8}\\
        };
    \end{scope}
    \path[draw] (A5-1-3.north west) -- (A5-1-4.north east) -- (B5-1-4.south east) -- (B5-1-4.south west) -- (A5-1-3.north west);
\end{tikzpicture}
\end{document}

Here \path[draw] groups 7s of the two matrices together. Is there any way to group them with a more "curvy" curve? i.e. by some curve that doesn't look so regular.

result

share|improve this question
add comment

2 Answers

up vote 13 down vote accepted

Like this (note that I replaced your last coordinate by -- cycle)?

\draw [rounded corners=5pt]
  (A5-1-3.north west) -- (A5-1-4.north east) --
  (B5-1-4.south east) -- (B5-1-4.south west) -- cycle;

round corners

or more like this?

\draw
  [decoration={random steps,segment length=6pt,amplitude=1.5pt},
   decorate, rounded corners=2pt]
  (A5-1-3.north west) -- (A5-1-4.north east) --
  (B5-1-4.south east) -- (B5-1-4.south west) -- cycle

zig-zag

I’d prefer the first one because it looks better matching to the style of printed text. The latter seems like some one attacked your paper ;-)

PS: I don’t know why the zig zag curve doesn’t close itself maybe one can fix this, please?

share|improve this answer
    
Instead of cycle you can just repeat the first point to close the shape. –  percusse Jan 10 '12 at 2:15
2  
@percusse: Yeah I know but that doesn’t give a rounded corner at this point too. –  Tobi Jan 10 '12 at 19:20
add comment

Replace the last line with:

\draw plot [smooth cycle,tension=0.3] coordinates {(A5-1-3.north west)  (A5-1-4.north east)  (B5-1-4.south east) (B5-1-4.south west)};

The option smooth cycle results in the points to be closed using a smooth curve (so you don't include the initial point twice as was the case in your original code).

The tension can be adjusted to suit. Also refer to Easy curves in TikZ.

enter image description here

\documentclass{standalone}
\usepackage{comment}

\usepackage{tikz,pgf}

\usetikzlibrary{fit,scopes,calc,matrix,positioning,decorations.pathmorphing}

\begin{document}

\begin{tikzpicture}
    \begin{scope}
            \matrix (A5) [matrix of nodes, ampersand replacement = \&] {
                {7}  \& {2} \& {7} \& {7} \& {2} \& {8}\\
            };
    \end{scope}
    \begin{scope}
        \matrix (B5) at ([yshift=-2.5cm]A5-1-1.south) [anchor=B5-1-1.north, matrix of nodes, ampersand replacement = \&] {
            {12} \& {7} \& {2} \& {7} \& {2} \& {8}\\
        };
    \end{scope}
\draw plot [smooth cycle,tension=0.3] coordinates {(A5-1-3.north west)  (A5-1-4.north east)  (B5-1-4.south east) (B5-1-4.south west)};
\end{tikzpicture}
\end{document}
share|improve this answer
    
This doesn't look too good for the start/end point, is there any way to fix that? –  Torbjørn T. Jan 9 '12 at 22:06
    
@TorbjørnT.: Have adjusted the code to fix this. Basically use smooth cycle and only list each point once. –  Peter Grill Jan 9 '12 at 22:17
    
Great, smooth cycle had escaped my attention. –  Torbjørn T. Jan 9 '12 at 22:38
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.