share
TeX - LaTeXPowerPoint's "Smart Art" for TikZ?
[+105] [1] krlmlr
[2012-10-19 12:23:18]
[ tikz-pgf beamer diagrams ]
[ https://tex.stackexchange.com/questions/78310/powerpoints-smart-art-for-tikz ]

This question led to a new package:
smartdiagram [1]

I haven't been using PowerPoint for years, but today I immediately fell in love with its "Smart Art" feature (2010 version of PowerPoint). The idea is that an (indented) bullet list is transformed automatically into a process diagram, a tree, a Venn diagram and whatnot. This allows creating simple yet expressive graphics in less than one minute.

Input:

Output:

Result of "Block cycle" smart art in PowerPoint

I know that TikZ already contains code for most shapes needed to build these graphics. What would be missing is a preprocessor to convert these bulletted list to TikZ code, perhaps within (Lua)LaTeX or as standalone preprocessor. (Of course, "normal" LaTeX syntax would do just as well.) Is anyone aware of such a tool?

EDIT: Of course, TikZ can draw Lindenmayer systems, petri nets, automata etc. -- difficult to do that with PowerPoint. But, say, what about a "Process" library that would visualize process chains based on a simple syntax?

EDIT^2: Of course, we could also turn this question into a collection of diagram-producing commands, and later bundle it as something pluggable, like a package/library!

EDIT^3: The above circular process diagram is not the only "smart art" design available. There are other examples, some are more useful, some less. What is your favorite?

But this is already available upon chains library anyway. What you want to have is to change the color and you are done. I don't think such a library would do any good. - percusse
(6) +1 for making such a package. I am using Beamer for all my presentations and would love such a feature. I have never written a package before but count me in on this one. - Ingo
@percusse: The "issue" here is that chains is far too powerful for just a simple diagram. Why do you think an abstraction layer that removes most of the complexity for the sake of a simpler usage is useless? Did you have a chance to look at what PowerPoint can do? - krlmlr
I'd totally love such a kind of library. Thumbs up! - Stephan Lehmke
@user946850: what I didn't clearly understand is if you really want the input should be typeset by the user as a, say, itemize environment and transformed in someway in the picture. Was your idea like this? - Claudio Fiandrino
I didn't say useless. I'm just saying that this functionality is already present without any special name. If you wish, you can parse an array and place your nodes in a macro. So a library is the redundant one. Otherwise it is certainly possible as shown in the answer. Besides that yes I'm aware of PPT functionality and that's why I use beamer. - percusse
Kind of duplicate of: High level macros and environments based on Tikz. Well, not with respect to the question, but the answer from Alain Matthes (better known as Altermundus). - Daniel
@ClaudioFiandrino: The way you specify the input in your implementation is just fine. Perhaps it should be possible to specify optional parameters with the [] syntax. - krlmlr
@Daniel: Must have missed that in my coarse search. The two diagrams proposed there as answer should be integrated in such a "high level" macro package. - krlmlr
[+98] [2012-10-19 13:08:53] Claudio Fiandrino [ACCEPTED]

Here is one possibility: it's based on a list, but not on itemize environments. Indeed I recall Arrows coordinates in TikZ [1] and adapted the things to:

  • create simply the diagram
  • create the diagram automatically overlay aware.

Now you have basically to insert your list inside a command \smartart or \smartartov (for the automatic animation), but I don't know how much you will find the answer suitable for your needs.

Here is the code:

\documentclass{beamer}  
\usepackage{lmodern}
\usepackage{tikz}

\usetikzlibrary{calc,shadows} 
\makeatletter 
\@namedef{color@1}{red!30}
\@namedef{color@2}{cyan!30}   
\@namedef{color@3}{blue!30} 
\@namedef{color@4}{green!30}  
\@namedef{color@5}{magenta!30} 
\@namedef{color@6}{yellow!30}    
\@namedef{color@7}{orange!30}    
\@namedef{color@8}{violet!30}   

\newcommand{\smartart}[1]{%
\begin{tikzpicture}[every node/.style={align=center}]  

\foreach \gritem [count=\xi] in {#1}  {\global\let\maxgritem\xi}  

\foreach \gritem [count=\xi] in {#1}
{% 
\pgfmathtruncatemacro{\angle}{360/\maxgritem*\xi}
\edef\col{\@nameuse{color@\xi}}
\node[rectangle,
    rounded corners,
     thick,
     draw=gray,
     top color= white,
     bottom color=\col,
     drop shadow,
     text width=1.75cm,
     minimum width=2cm,
     minimum height=1cm,
     font=\small] (satellite\xi) at (\angle:2.75cm) {\gritem };
}%

\foreach \gritem [count=\xi] in {#1}
{% 
\pgfmathtruncatemacro{\xj}{mod(\xi, \maxgritem) + 1)} 
\edef\col{\@nameuse{color@\xj}}
\draw[<-,>=stealth,line width=.1cm,\col,shorten <=0.3cm,shorten >=0.3cm] (satellite\xj) to[bend left] (satellite\xi);
}%
\end{tikzpicture}  
}%

\tikzset{
    invisible/.style={opacity=0},
    visible on/.style={alt=#1{}{invisible}},
    alt/.code args={<#1>#2#3}{%
      \alt<#1>{\pgfkeysalso{#2}}{\pgfkeysalso{#3}} % \pgfkeysalso doesn't change the path
    },
  }


\newcommand{\smartartov}[1]{%
\begin{tikzpicture}[every node/.style={align=center}]  

\foreach \gritem [count=\xi] in {#1}  {\global\let\maxgritem\xi}  

\foreach \gritem [count=\xi] in {#1}
{% 
\pgfmathtruncatemacro{\angle}{360/\maxgritem*\xi}
\edef\col{\@nameuse{color@\xi}}
\node[rectangle,
    rounded corners,
     thick,
     draw=gray,
     top color= white,
     bottom color=\col,
     drop shadow={visible on=<\xi->},
     text width=1.75cm,
     minimum width=2cm,
     minimum height=1cm,
     font=\small,
     visible on=<\xi->] (satellite\xi) at (\angle:2.75cm) {\gritem };
}%

\foreach \gritem [count=\xi] in {#1}
{% 
\pgfmathtruncatemacro{\xj}{mod(\xi, \maxgritem) + 1)}
\pgfmathtruncatemacro{\adv}{\xi + 1)}
\edef\col{\@nameuse{color@\xi}}
\draw[<-,>=stealth,line width=.1cm,\col,shorten <=0.3cm,shorten >=0.3cm,
visible on=<\adv->] (satellite\xj) to[bend left] (satellite\xi);
}%
\end{tikzpicture}  
}%
\makeatother

\begin{document}
\begin{frame}{Smart art}
\begin{center}
\smartartov{Set up~/ Adapt,Run,Analyze,Modify~/ Add}
\end{center}
\end{frame}

\end{document}

The diagram created by means of \smartart is:

enter image description here

The animation created by means of \smartartov:

enter image description here


I've seen EDIT^3, and I agree that one could also display differently the diagram, for example as a standard flow chart. A couple of weeks ago I built a library to draw switching architectures ( link [2]) in which main problem was similar, how to display automatically in a vertical fashion a given number of modules. Putting things together, two new commands are available:

  • \smartartflow to create the flow diagram
  • \smartartflowov to create the flow diagram automatically overlay aware.

The code:

\documentclass{beamer}  
\usepackage{lmodern}
\usepackage{tikz}

\usetikzlibrary{calc,shadows} 
\makeatletter 
\@namedef{color@1}{red!30}
\@namedef{color@2}{cyan!30}   
\@namedef{color@3}{blue!30} 
\@namedef{color@4}{green!30}  
\@namedef{color@5}{magenta!30} 
\@namedef{color@6}{yellow!30}    
\@namedef{color@7}{orange!30}    
\@namedef{color@8}{violet!30}   

\pgfmathsetmacro{\moduleysep}{1.2} % default value
\newcommand{\setmoduleysep}[1]{\pgfmathsetmacro{\moduleysep}{#1}}


\newcommand{\smartartflow}[1]{%
\begin{tikzpicture}[every node/.style={align=center}]  

\foreach \gritem [count=\xi] in {#1}  {\global\let\maxgritem\xi}  

\foreach \gritem [count=\xi] in {#1}
{%
\edef\col{\@nameuse{color@\xi}}
\path let \n1 = {int(0-\xi)}, \n2={0-\xi*\moduleysep}
    in node[rectangle,
    rounded corners,
     thick,
     draw=gray,
     top color= white,
     bottom color=\col,
     drop shadow,
     text width=1.75cm,
     minimum width=2cm,
     minimum height=1cm,
     font=\small] (satellite\xi) at +(0,\n2) {\gritem};

}%

\foreach \gritem [count=\xi] in {#1}
{% 
\pgfmathtruncatemacro{\xj}{mod(\xi, \maxgritem) + 1)} 
\edef\col{\@nameuse{color@\xj}}
\ifnum\xi<\maxgritem
\draw[<-,>=stealth,line width=.1cm,\col,] (satellite\xj) -- (satellite\xi);
\fi

\ifnum\xi=\maxgritem
\draw[<-,>=stealth,line width=.1cm,\col,] (satellite\xj.east)--($(satellite\xj.east)+(1,0)$) |- (satellite\xi);
\fi
}%

\end{tikzpicture}  
}

\tikzset{
    invisible/.style={opacity=0},
    visible on/.style={alt=#1{}{invisible}},
    alt/.code args={<#1>#2#3}{%
      \alt<#1>{\pgfkeysalso{#2}}{\pgfkeysalso{#3}} % \pgfkeysalso doesn't change the path
    },
  }

\newcommand{\smartartflowov}[1]{%
\begin{tikzpicture}[every node/.style={align=center}]  

\foreach \gritem [count=\xi] in {#1}  {\global\let\maxgritem\xi}  

\foreach \gritem [count=\xi] in {#1}
{%
\edef\col{\@nameuse{color@\xi}}
\path let \n1 = {int(0-\xi)}, \n2={0-\xi*\moduleysep}
    in node[rectangle,
    rounded corners,
     thick,
     draw=gray,
     top color= white,
     bottom color=\col,
     drop shadow={visible on=<\xi->},
     text width=1.75cm,
     minimum width=2cm,
     minimum height=1cm,
     font=\small,
     visible on=<\xi->] (satellite\xi) at +(0,\n2) {\gritem};

}%

\foreach \gritem [count=\xi] in {#1}
{% 
\pgfmathtruncatemacro{\adv}{\xi + 1)}
\pgfmathtruncatemacro{\xj}{mod(\xi, \maxgritem) + 1)} 
\edef\col{\@nameuse{color@\xj}}
\ifnum\xi<\maxgritem
\draw[<-,>=stealth,line width=.1cm,\col,visible on=<\adv->] (satellite\xj) -- (satellite\xi);
\fi

\ifnum\xi=\maxgritem
\draw[<-,>=stealth,line width=.1cm,\col,visible on=<\adv->] (satellite\xj.east)--($(satellite\xj.east)+(1,0)$) |- (satellite\xi);
\fi
}%

\end{tikzpicture}  
}
\makeatother

\begin{document}
\begin{frame}{Smart art flow}
\setmoduleysep{1.75} % to adjust the module separation
\begin{center}
\smartartflowov{Set up~/ Adapt,{Run, Compile},Analyze,Modify~/ Add, Build}
\end{center}
\end{frame}

\end{document}

The flow diagram created by means of \smartartflow is:

enter image description here

The animation created by means of \smartartflowov:

enter image description here


The code developed in the answer has been the base of the package smartdiagram [3]. Its macros are built on top of TikZ which is built on top of PGF: ok we can graphically see this with a priority descriptive diagram.

The code:

\documentclass{beamer}
\usepackage{smartdiagram}
\begin{document}
\begin{frame}
\begin{center}
\smartdiagramset{set color list={blue!50!cyan,green!60!lime,orange!50!red},
descriptive items y sep=1.5}
\smartdiagramanimated[priority descriptive diagram]{PGF,Ti\textit{k}Z,Smartdiagram}
\end{center}
\end{frame}
\end{document}

The result:

enter image description here

One point not yet well documented is the possibility of declaring a priori styles, for example when you want to repeat several times a diagram with the same properties. So it is sufficient to declare:

\smartdiagramset{diagram style/.style={module shape=diamond,font=\scriptsize,
module minimum width=1cm,module minimum height=1cm,text width=1cm}}

Then a possible use is:

\documentclass[11pt,a4paper]{article}
\usepackage{smartdiagram}
\usetikzlibrary{shapes.geometric} % for the diamond
\smartdiagramset{diagram style/.style={module shape=diamond,font=\scriptsize,
module minimum width=1cm,module minimum height=1cm,text width=1cm}}
\begin{document}
\begin{center}
\smartdiagramset{diagram style, arrow tip=to}
\smartdiagram[circular diagram]{Do, This, Only,For, Me}
\end{center}
\begin{center}
\smartdiagramset{diagram style, module y sep=2.5}
\smartdiagram[flow diagram]{Do, This,For, Me}
\end{center}
\end{document}
[1] https://tex.stackexchange.com/questions/52961/arrows-coordinates-in-tikz
[2] https://github.com/cfiandra/Sa-TikZ
[3] http://www.ctan.org/pkg/smartdiagram

(12) This is very nice. Clearly demonstrates that a package with abstraction macros is very possible. I can use this immediately with my lesson plans. And it will be a demonstration in the Spring with my "Technical Writing with LaTeX" class for freshman math majors. - R. Schumacher
(2) @R.Schumacher: thanks, I'm honored, but most the credit should go to Alain Matthes and Mohsen. :) The only new thing here is just the method to make the diagram overlay-aware. - Claudio Fiandrino
Beautiful! Is there a way to get commas into a node? - krlmlr
(3) @user946850: yes, you should enclose in {} the label; for example: \smartartov{{Build,Set up~/ Adapt},Run,Analyze,Modify~/ Add} - Claudio Fiandrino
(11) Smells to me like a new package.................... :-) - azetina
Why don't you add the second diagram type as a separate answer? Also, I'm not sure if SmartArt is a trademark -- it would be safest to avoid the word and call it different, say, "simple diagram"? - krlmlr
@user946850: the principle is the same.. why add a different answer? Notice that there are other methods to achieve a similar flow diagram (exploiting the library chains for example), so personally I post two answers on the same question if and only if the approaches used are different. For the name.. well, at the moment I did not had nothing better in mind, but I will change it soon (or if you prefer feel free to edit my answer). - Claudio Fiandrino
The two diagrams you have built share the principle, but the layout is different. I would suggest making one answer per layout -- "Smart Art" has many other layouts, some of which I'd find helpful to have in TikZ, too. - krlmlr
I see your point, but I don't think it's useful create an answer per diagram, so I won't split it. If you are interested in other layouts, feel free to edit the question being more specific. You can also try yourself to create new layouts, now you should have some more base to do so. :) - Claudio Fiandrino
Claudio, this is simply fantastic! I would like to point you also to this question, where Alain Matthes (better known as Altermundus) provides a similar solution, but again with a very different layout. I would love to see all that merged into one package. - Daniel
(3) Well, as we are already dreaming: What I would love to see is a package that provides a "generic engine" for smart arts that then can be configured via a pgf-keys interface, so that provided layouts can easily be configured by styles and new layouts can also be implemented as styles. Something in the spirit of the TikZ libraries, such as decorations or shapes. - Daniel
@Daniel: thanks for nice words! :) To be honest, I'm working on it (in the spare time or during the pc is doing my theses simulations) and I'm confident to have sooner a first release. - Claudio Fiandrino
Wow, another proof that I'm prejudiced against high-level TikZ constructions :) Looks great. - percusse
(1) @percusse: thanks! Well, there are a couple of things to adjust (some key re-order in principle) and some ideas to be implemented: for example introduce the possibility of decide the direction of flow diagrams (vertical/horizontal) and of circular diagrams (clockwise/counterclockwise). I'm thinking about splitting the first argument, e.g : \smartdiagram[flow diagram:vertical]{..}. But there's time (after the thesis)... also because the answer isn't even accepted. - Claudio Fiandrino
@ClaudioFiandrino Thank you for this wonderful package. It really saved me a lot of time. One issue I frequently run into when writing in German - a language with a large number of long, composited words - is that TikZ, and in term smartdiagram, does not hyphenate the module contents. This seems to be because by default Tex does not hyphenate the first word of a paragraph. To troubleshoot this you can add \hspace{0pt} in front of each label, but this is tedious. Is there any way you could implement this? - Glutanimate
(1) Yes, of course, thanks for pointing me this. I'm planning to have sooner version 0.3 adding features from TikZ: adding nodes to a circular diagram from smartdiagram package and from your other question about the arrow tips, so I'll try to implement also this. - Claudio Fiandrino
Great package! I was wondering if there is top-down version of the priority descriptive diagram (basically with a reversed arrow)? Are there options to disable the shadows and replace the color gradient filling by a solid filling? - user61658
@jpmath: Thank you for your interest in the package! Unfortunately, it does not exists a top-down version for the priority diagram (though it can be implemented quite easily). Disabling the shadows is a little bit tricky while to have solid filling you have to modify the module style. - Claudio Fiandrino
Thanks for your reply! I tried to find the option for the module style, but was unable to. Could you give me a hint how to get the solid filling? - user61658
@ClaudioFiandrino Would it maybe possible to remove the \pause from the smartdiagram package? They make things like beamer footlines invisible, see tex.stackexchange.com/q/569232/36296 Instead one could e.g. use \visible<+->{} around the nodes. - samcarter_is_at_topanswers.xyz
@ClaudioFiandrino Is there github/gitlab repo for smartdiagram? - samcarter_is_at_topanswers.xyz
@samcarter_is_at_topanswers.xyz: Nope, it was released only on CTAN. - Claudio Fiandrino
@ClaudioFiandrino Ah, ok, I was just wondering if there is some place to make a pull request to fix the problem with the \pauses - samcarter_is_at_topanswers.xyz
1