[Tex/LaTex] Fit to content in model of smart diagrams using smartdiagram package

resizesmartdiagramtikz-pgf

The question is about resizing modules in smart diagrams (package: smartdiagram).
The following code

\smartdiagram[flow diagram:horizontal]{A,BB,CCC,DDDD}

produces horizontal flow diagram. But Module size doesn't fit content. Is it possible to fit the module size (block size) according to its content. For example first module will have the least size and the last module will have the largest size.

Best Answer

The smartdiagram package does not provide such an option. However, as the modules are just tikz nodes you can quite easily edit the style defined by the package used by the package to achieve a variable module size. The relevant key here is text width, as this puts the text of a node in a box of at least the given width.

\documentclass{article}
\usepackage{smartdiagram}
\makeatletter % N.B.
\tikzset{module/.style={%
      \pgfkeysvalueof{/smart diagram/module shape},
      thick,
      draw=\sm@core@bordercolor,
      top color=white,
      bottom color=\col,
      text=\sm@core@textcolor,
      % text width=\sm@core@moduletextwidth, % Only necessary change
      minimum width=\sm@core@modulewidth,
      minimum height=\sm@core@moduleheight,
      font=\sm@core@modulefontsize,
      \sm@core@borderdecoration
   },
   diagram arrow type/.style={%
      \sm@core@arrowstyle,
      >=\sm@core@arrowtip,
      line width=\sm@core@arrowlinewidth,
      \col
   },%
}
\makeatother
\begin{document}
% Set minimums so module sizes are reasonable
\smartdiagramset{module minimum height=1cm,% initial: 1cm
                module minimum width=0.8cm,% initial: 2cm
                module x sep=2}% initial 2.75
\smartdiagram[flow diagram:horizontal]{A,BB,CCC,DDDD}
\end{document}

I've simply commented out the key. With this change, you will probably want to set module minimum width and height, which can be done though the interface provided by the smartdiagram package in the usual way (\smartdiagramset). I've also reduced module x sep, so as to avoid unseemly gaps between the now smaller modules.

Output:

enter image description here

Related Question