LaTeX forum ⇒ Graphics, Figures & Tablestikz mindmap, defining environments or commands

Information and discussion about graphics, figures & tables in LaTeX documents.
migf
Posts: 13
Joined: Mon Feb 18, 2013 2:33 pm

tikz mindmap, defining environments or commands

Postby migf » Wed Oct 31, 2018 3:45 pm

Hello,

I'm starting using tikz for drawing a lot of mindmaps and I need environments or commands to simplify the task. So I
defined an environment for a mindmap like this:
  1. \newenvironment{tree}[2]{
  2. \begin{center}
  3. \tikz \draw (0,-10) node [anchor=east,fill=orange!20] {some title};
  4. \tikz[mindmap,concept color=black,text=white]
  5. \node [concept] {\small #1\\#2}
  6. }{
  7. ;
  8. \end{center}
  9. }

and this allows me to use to add children nodes like this
  1. \begin{tree}{ABC}{XYZ}
  2. child[concept color=blue,grow=0] {node[concept] {Y20}}
  3. child[concept color=blue,grow=-180] {node[concept] {Y200}}
  4. \end{tree}


However all my attempts at defining a command of environment to add a child failed with tikz complaining about having to give up on the path, and a possible missing semicolon. Here is what I tried out as an environment, and also as a command:
  1. \newenvironment{tchild}[3]{
  2. child[concept color=#2,grow=#3] {node[concept] {#1}}
  3. }{
  4. }


Using a tikzpicture in the tree environment did not work:
  1. \newenvironment{treep}[2]{
  2. \begin{center}
  3. \begin{tikzpicture}[mindmap,concept color=black,text=white]
  4. \draw (0,-10) node [anchor=east,fill=orange!20] {some title};
  5. \node [concept] {\small #1\\#2}
  6. }{
  7. \end{tikzpicture}
  8. \end{center}
  9.  
  10. }


What am I doing wrong? Or is it the case I have to use some kind of preprocessor before running LaTeX?

Thanks in advance for any help!

This is a minimal mostly-non-working example:

  1. \documentclass[10pt]{report}
  2.  
  3. \usepackage{xcolor}
  4. \usepackage{tikz}
  5. \usetikzlibrary{mindmap}
  6.  
  7. \newenvironment{tree}[2]{
  8.  
  9. \begin{center}
  10. \tikz \draw (0,-10) node [anchor=east,fill=orange!20] {some title};
  11. \tikz[mindmap,concept color=black,text=white]
  12. \node [concept] {\small #1\\#2}
  13. }{
  14. ;
  15. \end{center}
  16.  
  17. }
  18.  
  19. \newenvironment{treep}[2]{
  20.  
  21. \begin{center}
  22. \begin{tikzpicture}[mindmap,concept color=black,text=white]
  23. \draw (0,-10) node [anchor=east,fill=orange!20] {some title};
  24. \node [concept] {\small #1\\#2}
  25. }{
  26. \end{tikzpicture}
  27. \end{center}
  28.  
  29. }
  30.  
  31. %%%% this fails, also as command
  32. % name, color, position
  33. \newenvironment{tchild}[3]{
  34. child[concept color=#2,grow=#3]
  35. {node[concept] {#1}}
  36. }{
  37. }
  38.  
  39. \begin{document}
  40.  
  41. This works:
  42.  
  43. \begin{verbatim}
  44. \begin{tree}{ABC}{XYZ}
  45. child[concept color=blue,grow=0] {node[concept] {Y20}}
  46. child[concept color=blue,grow=-180] {node[concept] {Y200}}
  47. \end{tree}
  48. \end{verbatim}
  49.  
  50. \begin{tree}{ABC}{XYZ}
  51. child[concept color=blue,grow=0] {node[concept] {Y20}}
  52. child[concept color=blue,grow=-180] {node[concept] {Y200}}
  53. \end{tree}
  54.  
  55. But not this:
  56. \begin{verbatim}
  57. \begin{treep}{ABC}{XYZ}
  58. child[concept color=blue,grow=0] {node[concept] {Y20}}
  59. child[concept color=blue,grow=-180] {node[concept] {Y200}}
  60. \end{treep}
  61. \end{verbatim}
  62.  
  63. nor this:
  64. \begin{verbatim}
  65. \begin{treep}{ABC}{XYZ}
  66. \begin{tchild}{Y20}{blue}{0}
  67. \end{tchild}
  68. \begin{tchild}{Y200}{}{blue}{-180}
  69. \end{tchild}
  70. \end{treep}
  71. \end{verbatim}
  72.  
  73. nor this:
  74. \begin{verbatim}
  75. \begin{tree}{ABC}{XYZ}
  76. \begin{tchild}{Y20}{blue}{0}
  77. \end{tchild}
  78. \begin{tchild}{Y200}{}{blue}{-180}
  79. \end{tchild}
  80. \end{tree}
  81. \end{verbatim}
  82.  
  83. \end{document}

Return to “Graphics, Figures & Tables”

Who is online

Users browsing this forum: Baidu [Spider] and 8 guests