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.

There is a node-to-node path and I want a text to be aligned to it. Also, [xshift=5mm] and [xshift=-5mm], which is supposed to ensure that the path ends do not touch the node boundary, doesn't seem to have any effect. I read the p.338-340 of the Manual.

%
%
%
\documentclass{standalone}

\usepackage{tikz,pgf}

\usetikzlibrary{decorations.markings,%
    snakes,fit,scopes,arrows,calc,shapes.misc,%
    shapes.arrows,chains,matrix,positioning,decorations.pathmorphing,shapes,backgrounds,%
    decorations.text}

\begin{document}

\tikzset{
    fuzzy/.style = {decorate, decoration = {random steps, segment length = 0.5mm, amplitude = 0.15pt}},
    ns/.style = {
        rectangle,
        minimum size = 6mm, 
        rounded corners = 3mm,
        very thick,
        draw,
        font = \ttfamily,
        fuzzy
    }
}

\newcommand{\bbrect}[3]{\node[rectangle,fuzzy,draw,fit=(B-#1-1.north west) (B-#2-1.south east), inner sep = 0pt] (block#3) {}}
\newcommand{\cbl}[2]{\node[rectangle,fuzzy,draw,fit=(C-#1-1.north west) (C-#1-1.south east), inner sep = 0pt] (cblock#2) {}}

\begin{tikzpicture} [
        >=latex, thick, 
        /pgf/every decoration/.style = {/tikz/sharp corners}, minimum size = 6mm
    ]
    \ttfamily
    \begin{scope}
            \matrix (B) [matrix of nodes, ampersand replacement = \&] {
                \hline
                {B}\\
                \hline
                {12}\\
                {7}\\
                    {2}\\
                {2}\\
                {2}\\
                {2}\\
                 {2}\\
                 {2}\\
                 {7}\\
                 {7}\\
                 {2}\\
                 {2}\\
                 {2}\\
                 {8}\\
                 {4}\\
                 {4}\\
                 {4}\\
                 {4}\\
                 {4}\\
                 {4}\\
                 {9}\\
                 {11}\\
                 {1}\\
                 {1}\\
                 {1}\\
                 {1}\\
                 {1}\\
                 {1}\\
                 {1}\\
                 {1}\\
                 {1}\\
                 {5}\\
                 {5}\\
                 {5}\\
                 {6}\\
                 {6}\\
                 {6}\\
                 {10}\\
                 {3}\\
                 {3}\\
                 {3}\\
                 {0}\\
                 {0}\\
                 {0}\\
                 {0}\\
                 {0}\\
                 {0}\\
                 {0}\\
                 {0}\\
                 {0}\\
            };
            \bbrect{2}{2}{1};
            \bbrect{3}{3}{2};
            \bbrect{4}{9}{3};
            \bbrect{10}{11}{4};
            \bbrect{12}{14}{5};
            \bbrect{15}{15}{6};
            \bbrect{16}{21}{7};
            \bbrect{22}{22}{8};
            \bbrect{23}{23}{9};
            \bbrect{24}{32}{10};
            \bbrect{33}{35}{11};
            \bbrect{36}{38}{12};
            \bbrect{39}{39}{13};
            \bbrect{40}{42}{14};
            \bbrect{43}{51}{15};
        \end{scope}

        \begin{scope}[xshift = 5cm]
            \matrix (C) at ([xshift = 5cm]B-1-1.north east) [anchor=C-1-1.north west, matrix of nodes, ampersand replacement = \&] {
                \hline
                {C}\\
                \hline
                {12}\\
                {7}\\
                {2}\\
                {7}\\
                {2}\\
                {8}\\
                {4}\\
                {9}\\
                {11}\\
                {1}\\
                {5}\\
                {6}\\
                {10}\\
                {3}\\       
                {0}\\
            };  
            \cbl{2}{1};
            \cbl{3}{2};
            \cbl{4}{3};
            \cbl{5}{4};
            \cbl{6}{5};
            \cbl{7}{6};
            \cbl{8}{7};
            \cbl{9}{8};
            \cbl{10}{9};
            \cbl{11}{10};
            \cbl{12}{11};
            \cbl{13}{12};
            \cbl{14}{13};
            \cbl{15}{14};
            \cbl{16}{15};
    \end{scope}

    \draw[postaction={decoration={text along path,text = {merging a contiguous run},text align=fit to path},decorate}]
        ([xshift=5mm]block7) -- ([xshift=-5mm]$(cblock7.north)!.5!(cblock7.south)$);

    \begin{pgfonlayer}{background}
        \foreach \i in {1,...,15} {
            \path[draw,dotted] (block\i.north east) -- (cblock\i.north west);
            \path[draw,dotted] (block\i.south east) -- (cblock\i.south west);
        }
    \end{pgfonlayer}

\end{tikzpicture}

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

1 Answer

up vote 6 down vote accepted

To avoid touching the path's ends, you could add pre length and post length options do the decoration, such as:

\draw[postaction={decoration={text along path,
  text = {merging a contiguous run}, text align=fit to path,
  pre length=2em, post length=2em},decorate}]
    (block7) -- ($(cblock7.north)!.5!(cblock7.south)$);
share|improve this answer
    
pre length option was useful; text align wouldn't work ("I don't know the key /pgf/decoration/text align"), gave up the idea of snakes so used \path rather than \draw. The text going in the desired direction is there, so I accept. –  Ilonpilaaja Jan 8 '12 at 16:45
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.