Graphics, Figures & Tablestikz mindmap, defining environments or commands

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

tikz mindmap, defining environments or commands

Post by migf »

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:

Code: Select all

\newenvironment{tree}[2]{
\begin{center}
\tikz \draw (0,-10) node [anchor=east,fill=orange!20] {some title};
\tikz[mindmap,concept color=black,text=white]
\node [concept] {\small #1\\#2}
}{
  ;
\end{center}
}
and this allows me to use to add children nodes like this

Code: Select all

\begin{tree}{ABC}{XYZ}
   child[concept color=blue,grow=0] {node[concept] {Y20}}
   child[concept color=blue,grow=-180] {node[concept] {Y200}}
\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:

Code: Select all

\newenvironment{tchild}[3]{
  child[concept color=#2,grow=#3] {node[concept] {#1}}
}{
}
Using a tikzpicture in the tree environment did not work:

Code: Select all

\newenvironment{treep}[2]{
\begin{center}
 \begin{tikzpicture}[mindmap,concept color=black,text=white]
  \draw (0,-10) node [anchor=east,fill=orange!20] {some title};
  \node [concept] {\small #1\\#2}
}{
 \end{tikzpicture}
\end{center}

}
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:

Code: Select all

\documentclass[10pt]{report}

\usepackage{xcolor}
\usepackage{tikz}
\usetikzlibrary{mindmap}

\newenvironment{tree}[2]{

\begin{center}
\tikz \draw (0,-10) node [anchor=east,fill=orange!20] {some title};
\tikz[mindmap,concept color=black,text=white]
\node [concept] {\small #1\\#2}
}{
  ;
\end{center}

}

\newenvironment{treep}[2]{

\begin{center}
 \begin{tikzpicture}[mindmap,concept color=black,text=white]
  \draw (0,-10) node [anchor=east,fill=orange!20] {some title};
  \node [concept] {\small #1\\#2}
}{
 \end{tikzpicture}
\end{center}

}

%%%% this fails, also as command
 % name, color, position
\newenvironment{tchild}[3]{
  child[concept color=#2,grow=#3]
  {node[concept] {#1}}
}{
}

\begin{document}

This works:

\begin{verbatim}
\begin{tree}{ABC}{XYZ}
   child[concept color=blue,grow=0] {node[concept] {Y20}}
   child[concept color=blue,grow=-180] {node[concept] {Y200}}
\end{tree}
\end{verbatim}

\begin{tree}{ABC}{XYZ}
   child[concept color=blue,grow=0] {node[concept] {Y20}}
   child[concept color=blue,grow=-180] {node[concept] {Y200}}
\end{tree}

But not this:
\begin{verbatim}
\begin{treep}{ABC}{XYZ}
   child[concept color=blue,grow=0] {node[concept] {Y20}}
   child[concept color=blue,grow=-180] {node[concept] {Y200}}
\end{treep}
\end{verbatim}

nor this:
\begin{verbatim}
\begin{treep}{ABC}{XYZ}
  \begin{tchild}{Y20}{blue}{0}
    \end{tchild}
  \begin{tchild}{Y200}{}{blue}{-180}
    \end{tchild}
\end{treep}
\end{verbatim}

nor this:
\begin{verbatim}
\begin{tree}{ABC}{XYZ}
  \begin{tchild}{Y20}{blue}{0}
    \end{tchild}
  \begin{tchild}{Y200}{}{blue}{-180}
    \end{tchild}
\end{tree}
\end{verbatim}

\end{document}

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

Post Reply