5

I am trying to do a chart with tikz, I get this

tikz chart

This is the latex script:

 \documentclass[12pt,twoside]{report} 
%%%<
\usepackage[spanish]{babel}
%interprete de idioma castellano
\usepackage[utf8]{inputenc} %relacionado al input
\usepackage[T1]{fontenc} 
\usepackage{tikz}
\begin{document}

\begin{tikzpicture}[sibling distance=10em,
  every node/.style = {shape=rectangle, rounded corners,
    draw, align=center,
    top color=white, bottom color=blue!20}]]
  \node {Solvatación}
    child {{ node {Implícito} }
        child{ node {Cosmo} }}
    child {{ node {Explícito+Implícito}
      child { node {Solvateshell + Cosmo}
      child { node {Packmol + Cosmo} } }}};
\end{tikzpicture}
\end{document}

But I need this:

image2

cfr
  • 198,882
  • Don't you get a compilation error? – cfr Aug 24 '17 at 12:35
  • Yes, but it produces the image anyway, isn't it? @cfr –  Aug 24 '17 at 12:39
  • 1
    It produces an image, but it's not necessarily the correct one. You should always make sure your code doesn't throw any errors, even if the output by accident looks OK. – Torbjørn T. Aug 24 '17 at 12:42
  • @TorbjørnT. I am sorry –  Aug 24 '17 at 12:43
  • 2
    No need to be sorry, I wasn't angry or anything. It was just advice really. Errors mean that something is wrong, and it's in your best interest to fix them, because you can't be sure that the output you get is the output you intended to get. – Torbjørn T. Aug 24 '17 at 12:47
  • 1
    If you can't fix them, then ask a question which includes the text of the error message, as well as the code, and (almost always) somebody can tell you how to fix it. When you get an image anyway, it means TeX tries to carry on by guessing what might have been meant e.g. it adds something or removes something. That often gets the compilation to succeed, but, as @TorbjørnT. says, it is often not with the intended results ;). – cfr Aug 24 '17 at 12:51

1 Answers1

4

It is strange that you don't mention errors, as I get a compilation error with your code. Since you don't say, I don't know if this is the problem or not but I think you have too many curly brackets.

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[sibling distance=10em,
  every node/.style = {shape=rectangle, rounded corners, draw, align=center, top color=white, bottom color=blue!20},
  edge from parent/.append style={->}
  ]
  \node {Solvatación}
  child {
    node {Explícito+Implícito}
    child {
      node {Solvateshell\\+ Cosmo}
    }
    child {
      node {Packmol\\+ Cosmo}
    }
  }
  child {
    node {Implícito}
    child {
      node {Cosmo}
    }
  };
\end{tikzpicture}
\end{document}

fewer curly brackets for more tree

Personally, I'd use Forest.

\documentclass[border=10pt]{standalone}
\usepackage{forest}
\begin{document}
\begin{forest}
  for tree={
    rounded corners, draw, align=center, top color=white, bottom color=blue!20,
    edge+=->,
    l sep'+=10pt,
  },
  [Solvatación
    [Explícito+Implícito
      [Solvateshell + Cosmo]
      [Packmol + Cosmo]
    ]
    [Implícito
      [Cosmo]
    ]
  ]
\end{forest}
\end{document}

Forest solution

However, it certainly isn't necessary here.

cfr
  • 198,882
  • Great! Is possible to add "arrows" instead of "lines" conecting the blocks?a –  Aug 24 '17 at 12:36
  • @HernanMiraola For arrow tips in the first example, add edge from parent/.append style={->,>=stealth} to the tikzpicture options. – Torbjørn T. Aug 24 '17 at 12:43
  • I did that, but It doesn't work..@TorbjørnT. –  Aug 24 '17 at 12:46
  • @HernanMiraola Please see above. (It has arrows now.) If you want a different arrow tip, set it as Torbjørn T. suggests or use the now recommended arrows.meta library and -Stealth or -Latex or whatever. – cfr Aug 24 '17 at 12:46
  • @HernanMiraola It does work. I was posting exactly that change while Torbjørn T. was commenting, I think. – cfr Aug 24 '17 at 12:47
  • You are right I put an extra bracket. Thanks both @cfr –  Aug 24 '17 at 12:49
  • Incredibly it is not working. It returns ` Argument of \language@active@arg> has an extra }. \par l.20 }; I've run across a `}' that doesn't seem to match anything. For example, `\def\a#1{...}' and `\a}' would produce this error. If you simply proceed now, the `\par' that I've just inserted will cause me to report a runaway argument that might be the root of the problem. But if your `}' was spurious, just type `2' and it will go away.` –  Aug 24 '17 at 13:19
  • @HernanMiraola Do you mean it doesn't work in your real document or that precisely my code doesn't work in a new .tex file? If the former, have you tried loading the babel TikZ library, as I saw you'd updated your question to load Babel with Spanish. I think that enables short-hands, which cause TikZ problems. The babel library addresses that issue. – cfr Aug 24 '17 at 15:38
  • @HernanMiraola That is, add \usetikzlibrary{babel} in your preamble. – cfr Aug 24 '17 at 15:39
  • And is there any solution to use forest? (It worked for tikz, thanks). –  Aug 25 '17 at 01:08
  • @HernanMiraola Doesn't that work for Forest too? I'd assume it would. – cfr Aug 25 '17 at 01:09
  • No, it returns a similar error: `! Argument of \language@active@arg> has an extra }. \par l.16 \end{forest} I've run across a `}' that doesn't seem to match anything. For example, `\def\a#1{...}' and `\a}' would produce this error. If you simply proceed now, the `\par' that I've just inserted will cause me to report a runaway argument that might be the root of the problem. But if your `}' was spurious, just type `2' and it will go away. Runaway argument?` –  Aug 25 '17 at 01:13
  • 1
    I have made a new question: https://tex.stackexchange.com/questions/388093/problems-when-using-forest-with-mwe –  Aug 25 '17 at 01:35
  • In some hours I will have tex 2017 finally installed on debian. I can try what we were talking about, if not mistaken. Isn't it? –  Oct 03 '17 at 11:08
  • The fix I posted for Forest should work. @HernanMiraola The package author looked it over, I think. – cfr Oct 04 '17 at 03:36
  • Yes, I am not talking about this post but there was something you wanted to try with spanish language, maybe I am confused –  Oct 04 '17 at 03:39
  • @HernanMiraola Yes. My answer to the other question, I think. – cfr Oct 04 '17 at 03:40