2

I'm not sure what this problem is called so it's hard to search for information... When I use the tikz package sometimes part of the drawing does not show fully. Currently the code I am using for a curly brace is not showing its right side... Why?

The original code from where I took it had a picture that seemed to display correctly. This is not the first time that this has happened on my Textmate.

enter image description here

Here is a minimal working code that uses the template I am using and only shows the graph with problematic curling braces: http://pastebin.com/g4j7kKAF

\documentclass{standalone}
\usepackage{tikz}
    \usetikzlibrary{matrix}
    \usetikzlibrary{decorations.pathreplacing}    
        \tikzstyle{underbrace style}=[decorate,decoration={brace,raise=10mm,amplitude=5pt,mirror},color=black]    

\usepackage[brazilian]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\begin{document}

      \begin{tikzpicture}[%
        >=stealth,
        shorten >=2pt,
        thick
      ]
        \matrix (block) [%
          matrix of nodes,
          nodes={%
            draw,
            anchor=center,
            minimum width=2em,
            minimum height=1em
          }
        ] {%
          1 & 2 & \node[fill=gray!99]{8}; & \node[fill=gray!50]{3}; & 4 & 6 & 9\\
        };
%\node[fill=gray!50]{1};
        \path[->] (block-1-4.north) edge [bend right=30] (block-1-3.north)
                  (block-1-3.south) edge [bend right=30] (block-1-4.south);
        \draw (block-1-1.west) node[left=0.005cm,scale=0.9] {A:};                              
        \draw (block-1-2.south) node[below=0.1cm] {$\longleftarrow$};                  
        \draw (block-1-2.south) node[left=0.2cm,below=0.4cm,scale=0.6] {Ordenado};                          
        \draw (block-1-1.north) node[above=0.1cm,scale=0.7] {0};
        \draw (block-1-2.north) node[above=0.1cm,scale=0.7] {1};
        \draw (block-1-3.north) node[above=0.1cm,scale=0.7] {i=2};
        \draw (block-1-4.north) node[above=0.05cm,scale=0.7] {j=3};
        \draw (block-1-5.north) node[above=0.1cm,scale=0.7] {4};
        \draw (block-1-6.north) node[above=0.1cm,scale=0.7] {5};
        \draw (block-1-7.north) node[above=0.1cm,scale=0.7] {6};           
        \draw (block-1-2.south east) node[right=0.25cm,below=1.9cm] {$\longrightarrow$};            
        \draw [thin] (block-1-2.south east) +(0,-2) -- +(0,+2);        
        \draw (block-1-2.south east) node[right=0.25cm,below=2.1cm] {Fronteira};    
        \draw [underbrace style] (block-1-1.south west) -- (block-1-2.south east) node [left=0.8cm,below=1.05cm] {$A_{esquerdo}$};                   
        \draw [underbrace style] (block-1-2.south east) -- (block-1-7.south east) node [left=1.8cm,below=1.05cm] {$A_{direito}$};                           

      \end{tikzpicture}
\end{document}
  • 8
    Can you post your code that gives trouble? – user11232 Nov 30 '13 at 7:05
  • 2
    @closers: since the question has been asked recently, I would give to the OP the opportunity to add the problematic code before voting to close. – Claudio Fiandrino Nov 30 '13 at 9:59
  • 3
    If you are using tikzmark (the remember picture option) you will need to compile at least twice. If you are using tikzmark without remember picture you need to add it since it works only with that option. – Qrrbrbirlbel Nov 30 '13 at 10:06
  • @Claudio The code has been referenced. Any code will give the same problem. I will upload a picture of myself running the code, if you feel it is needed. – Oeufcoque Penteano Dec 1 '13 at 2:07
  • 1
    @OeufcoquePenteano: I'm sorry, but you should be more specific than "Any code will give the same problem.". Which code did you use (the question or the answer) and which code did you use to get the picture you posted? There could be a number of reasons why it's not working so to really detect the problem we need: a) the code you used, b) the errors you got. Don't be shy to post your code: anybody has to start somewhere. – Claudio Fiandrino Dec 1 '13 at 9:29
6

The problem is due to shorten >=2pt option. It makes all paths 2pt shorter, so decorated paths are also shorter than expected. Apply shorten >=0pt option to underbrace style paths and they will be long enough.

I've made some corrections to your code.

  1. It's better to use tikzset instead to tikzstyle: Should \tikzset or \tikzstyle be used to define TikZ styles?
  2. Don't use \node inside a matrix of nodes. You can change node options with syntax |[options]|.

You corrected code is:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{matrix}
\usetikzlibrary{decorations.pathreplacing}    
\tikzset{underbrace style/.style = 
{decorate, 
 decoration={brace, raise=10mm, amplitude=5pt, mirror},
 shorten >=0pt, color=black}}
\usepackage[brazilian]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\begin{document}
\begin{tikzpicture}[%
        >=stealth,
        shorten >=2pt,
        thick
      ]
\matrix (block) [%
      matrix of nodes,
      nodes={%
            draw,
            anchor=center,
            minimum width=2em,
            minimum height=1em
      }
      ] 
{%
  1 & 2 & |[fill=gray!99]| 8 & |[fill=gray!50]| 3 & 4 & 6 & 9\\
};

\path[->] (block-1-4.north) edge [bend right=30] 
           (block-1-3.north)
          (block-1-3.south) edge [bend right=30] 
          (block-1-4.south);
\draw (block-1-1.west) node[left=0.005cm,scale=0.9] {A:};                              
\draw (block-1-2.south) node[below=0.1cm] {$\longleftarrow$};                  
\draw (block-1-2.south) node[left=0.2cm,below=0.4cm,scale=0.6] {Ordenado};                          
\draw (block-1-1.north) node[above=0.1cm,scale=0.7] {0};
\draw (block-1-2.north) node[above=0.1cm,scale=0.7] {1};
\draw (block-1-3.north) node[above=0.1cm,scale=0.7] {i=2};
\draw (block-1-4.north) node[above=0.05cm,scale=0.7] {j=3};
\draw (block-1-5.north) node[above=0.1cm,scale=0.7] {4};
\draw (block-1-6.north) node[above=0.1cm,scale=0.7] {5};
\draw (block-1-7.north) node[above=0.1cm,scale=0.7] {6};           
\draw (block-1-2.south east) node[right=0.25cm,below=1.9cm] {$\longrightarrow$};            
\draw [thin] (block-1-2.south east) +(0,-2) -- +(0,+2);        
\draw (block-1-2.south east) node[right=0.25cm,below=2.1cm] {Fronteira};    
\draw [underbrace style] (block-1-1.south west) -- (block-1-2.south east) node [left=0.8cm,below=1.05cm] {$A_{esquerdo}$};                   
\draw [underbrace style] (block-1-2.south east) -- (block-1-7.south east) node [left=1.8cm,below=1.05cm] {$A_{direito}$};                      
\end{tikzpicture}
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.