1

I am trying to represent a diagram with boxed like in the pictures:

enter image description here

So, 4 diagrams as showed below. The problem is that I do not know how to make them colored, with the math signs and the text in several lines. Specially, the diagram 3 seems more difficult.

Any advice or help?

Thanks to all :)

1

Another solution with TikZ chains

enter image description here

\documentclass{article} 
\usepackage{tikz}
\usetikzlibrary{chains}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[spanish]{babel}
\usepackage{lmodern}

\begin{document}

\begin{enumerate}
\item
\begin{tikzpicture}[start chain, 
    every node/.style={on chain},
    bloc/.style={fill=red!80!blue!70, 
        minimum width=3.5cm, minimum height=1.2cm, 
        text=white, font=\sffamily, align=center,   
        outer sep=0pt},
    simbol/.style={text=blue!80, 
        font=\bfseries\Large, outer sep=0pt},
    node distance=0pt,
    ]
    \node[bloc] {Gasto en\\ pensiones};
    \node[simbol] {=};
    \node[bloc, fill=green!80!black] {Ingresos del sistema de \\ pensiones};
\end{tikzpicture}

\item
\begin{tikzpicture}[start chain, 
    every node/.style={on chain},
    bloc/.style={fill=red!80!blue!70, 
        minimum width=1.8cm, minimum height=1.5cm, 
        text=white, font=\sffamily, align=center,   
        outer sep=0pt},
    simbol/.style={text=blue!80, 
        font=\bfseries\Large, outer sep=0pt},
    node distance = 0pt
    ]
    \node[bloc] {IRP};
    \node[simbol] {+};
    \node[bloc] {Crecimiento\\ número de \\ pensiones};
    \node[simbol] {+};
    \node[bloc] {Efecto\\ sustitución\\ (altas/bajas)};
    \node[simbol] {=};
    \node[bloc, fill=green!80!black] {Inflación};
    \node[simbol] {+};
    \node[bloc, fill=green!80!black] {Crecimiento\\ real de los\\ ingresos};
\end{tikzpicture}

\item
\begin{tikzpicture}[start chain,
    every node/.style={on chain},
    bloc/.style={fill=red!80!blue!70, 
        minimum width=1.7cm, minimum height=1.5cm, 
        text=white, font=\sffamily, align=center,   
        outer sep=0pt},
    simbol/.style={text=blue!80, 
        font=\bfseries\Large, outer sep=0pt,
        minimum height=1.5cm},
    node distance = 0pt
    ]
    \node[bloc] {IRP};
    \node[simbol] {=};
    \node[bloc, fill=blue!30] {Inflación};
    \node[simbol] {+};
    \node[bloc, fill=blue!30] {Crecimiento\\ real de los\\ ingresos};
    \node[simbol, fill=blue!30] {-};
    \node[bloc, fill=blue!30] {Crecimiento\\ número de \\ pensiones};
    \node[simbol, fill=blue!30] {-};
    \node[bloc, fill=blue!30] {Efecto\\ sustitución\\ (altas/bajas)};
\end{tikzpicture}

\item
\begin{tikzpicture}[start chain,
    bloc/.style={fill=red!80!blue!70, 
        minimum width=2.2cm, minimum height=1.5cm, 
        text=white, font=\sffamily, align=center,   
        outer sep=0pt},
    simbol/.style={text=blue!80, 
        font=\bfseries\Large, outer sep=0pt},
    lbl/.style={text=white, font=\sffamily, 
        align=center, outer sep=1mm,
        minimum width=2.2cm, fill=red!80!blue!70},
    node distance = 0pt
    ]
    \node[on chain, bloc, 
        label={[lbl]below:1,5\%}] {IRP};
    \node[on chain, simbol] {=};
    \node[on chain, bloc, fill=green!80!black, 
        label={[lbl,fill=green!80!black]below:1,5\%}] {Inflación};
    \node[on chain, simbol] {+};
    \node[on chain, bloc, fill=green!80!black,
        label={[lbl,fill=green!80!black]below:2,0\%}] {Crecimiento\\ real de los\\ ingresos};
    \node[on chain, simbol] {-};
    \node[on chain, bloc,
        label={[lbl]below:1,2\%}] {Crecimiento\\ número de \\ pensiones};
    \node[on chain, simbol] {-};
    \node[on chain, bloc,
        label={[lbl]below:0,8\%}] {Efecto\\ sustitución\\ (altas/bajas)};
\end{tikzpicture}
\end{enumerate}
\end{document}
3

I introduce \cbox[<width>]{<box-color>}[<text-color>]{<content>} (note there are two optional arguments) along with \bigeq, \bigplus, and \bigminus. I do some \cbox nesting (plus shenanigans with \bxht and \fboxsep in order to handle the large blue box).

\documentclass{article}
\usepackage[margin=1cm]{geometry}
\usepackage{xcolor}
\colorlet{red1}{red!80!blue!80}
\colorlet{green1}{green!80!black}
\colorlet{blue1}{blue!30}
\def\bxht{\dimexpr3\baselineskip\relax}
\def\bxwd{\dimexpr0.7in\relax}
\newcommand\cbox[2][\bxwd]{\def\boxwidth{#1}\def\boxcolor{#2}\cboxX}
\newcommand\cboxX[2][white]{\colorbox{\boxcolor}{%
  \rule[-.5\dimexpr\bxht-.7\ht\strutbox]{0pt}{\bxht}%
  \parbox[c]{\boxwidth}{\small\centering\color{#1}#2}}}
\newcommand\bigeq{\unskip\raisebox{-2pt}{\bfseries\color{blue!80}%
  \LARGE\boldmath${}={}$}\ignorespaces}
\newcommand\bigplus{\unskip\raisebox{-2pt}{\bfseries\color{blue!80}%
  \LARGE\boldmath${}+{}$}\ignorespaces}
\newcommand\bigminus{\unskip\raisebox{-2pt}{\bfseries\color{blue!80}%
  \LARGE\boldmath${}-{}$}\ignorespaces}
\begin{document}
\sffamily
1)\quad \cbox[1.3in]{red1}{Gasto en\\ pensiones} \bigeq
  \cbox[1.3in]{green1}{Ingresos del sistema de pensiones}\bigskip

2)\quad \cbox{red1}{IRP} \bigplus \cbox{red1}{Crecimiento numero de pensiones} 
  \bigplus \cbox{red1}{Efeto sustitucion (altas/bajas)} \bigeq
  \cbox{green1}{Inflacion} \bigplus 
  \cbox{green1}{Crecimiento real de los ingresos}\bigskip

3)\quad \cbox{red1}{IRP} \bigeq \cbox{blue1}[blue]{Inflacion} \bigplus
  \cbox[3in]{blue1}{\def\bxht{2\baselineskip}\hspace{-\fboxsep}%
    \cbox{blue1}[blue]{Crecimiento real de los ingresos} \bigminus 
    \cbox{blue1}[blue]{Crecimiento numero de pensiones}  \bigminus 
    \cbox{blue1}[blue]{Efeto sustitucion (altas/bajas)}}
  \bigskip

4)\quad \cbox{red1}{IRP}\bigeq\cbox{green1}{Inflacion}
  \bigplus\cbox{green1}{Crecimiento real de los ingresos}
  \bigminus%
  \cbox{red1}{Crecimiento numero de pensiones}\bigminus
  \cbox{red1}{Efeto sustitucion (altas/bajas)}\smallskip

\edef\bxht{.33\bxht}
\leavevmode\phantom{2)}\quad\cbox{red1}{1.5\%}\phantom{\bigeq}%
  \cbox{green1}{1.5\%}\phantom{\bigplus}\cbox{green1}{2.0\%}\phantom{\bigminus}%
  \cbox{red1}{1.2\%}\phantom{\bigminus}\cbox{red1}{0.8\%}
\end{document}

enter image description here

  • Wow!!! Quite advanced programming latex for me 'cause is the first time I see commands like \bxht, \bxwd and \dimexpr. Thanks a lot for the help!!! :) – José Jul 20 '16 at 7:25
  • @José \bxht and \bxwd are things I defined, to be used exclusively by the \cbox macro, designating the default height and width of the \cbox. \dimexpr is a TeX primative that says to evaluate what follows as a length dimension. By using these, when you write 2\bxht, you will get 2 x 0.7in = 1.4in dimension. Without the \dimexpr, 2\bxht would evaluate (by substitution) as 20.7in, which is quite different. – Steven B. Segletes Jul 20 '16 at 9:28
  • @José I should add that, furthermore, \dimexpr allows addition and subtraction operations in what follows, up to the end of the group or the first \relax, which terminates the \dimexpr. Thus, \dimexpr1pt+1pt\relax will produce the dimension 2pt, whereas without the \dimexpr, 1pt+1pt will not be added together, but will be kept as the string of characters. It will break code that is looking for a single dimension (unless you are using the calc package). – Steven B. Segletes Jul 20 '16 at 10:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.