# Increase vertical space for tikz boxes

Problem:

This problem is two-fold:

• How would I do in order to increase the top and bottom margin for the orange box where it says "Code if true"?
• How would I do in order to always align the orange and blue box to each other? If I change the text in the orange box it moves.

Minimal Working Example (MWE):

\documentclass[varwidth=20cm]{standalone}
\usepackage[T1]{fontenc}
\usepackage{tikz}

\definecolor{labelBlue}{cmyk}{1, 0.5, 0, 0.1}
\definecolor{labelPink}{cmyk}{0, 1, 0, 0}
\definecolor{labelGray}{cmyk}{0.6, 0.55, 0.55, 0.2}
\definecolor{labelOrange}{cmyk}{0, 0.8, 1, 0}

\newcommand{\mycolorbox}[2][gray]{\tikz[baseline=(n.base)] \node[rounded corners,white,node font=\sffamily,fill=#1,inner xsep=5pt](n){\mathstrut#2};}

\begin{document}
\mycolorbox[labelPink]{if}\nobreakspace\mycolorbox[labelBlue]{(condition)}\nobreakspace\mycolorbox{\textbraceleft}\\
\hspace*{20pt}\mycolorbox[labelOrange]{Code if true}\\
\mycolorbox{\textbraceright}
\end{document}


Above will produce:

Desired outcome:

• To be able to adjust top and bottom margin of the orange box.
• To align the orange box to the left so it is in line with the blue box.

• Instead of manual spacing, one easy way to align the boxes is to use a tabular; the inter-column space can be controlled with \tabcolsep (default=6pt); another option is to use \phantom, as in the second example code below.

• You can use the optional argument for \\ as in \\[1cm] to increase the vertical separation between boxes.

The code:

\documentclass[varwidth=20cm]{standalone}
\usepackage[T1]{fontenc}
\usepackage{tikz}

\definecolor{labelBlue}{cmyk}{1, 0.5, 0, 0.1}
\definecolor{labelPink}{cmyk}{0, 1, 0, 0}
\definecolor{labelGray}{cmyk}{0.6, 0.55, 0.55, 0.2}
\definecolor{labelOrange}{cmyk}{0, 0.8, 1, 0}

\newcommand{\mycolorbox}[2][gray]{\tikz[baseline=(n.base)] \node[rounded corners,white,node font=\sffamily,inner xsep=5pt,fill=#1](n){\mathstrut#2};}

\begin{document}

\setlength\tabcolsep{1pt}
\begin{tabular}{@{}lll@{}}
\mycolorbox[labelPink]{if} & \mycolorbox[labelBlue]{(condition)} & \mycolorbox{\textbraceleft}\\[0.5cm]
& \mycolorbox[labelOrange]{Code if true}\\[0.5cm]
\mycolorbox{\textbraceright}
\end{tabular}

\noindent
\mycolorbox[labelPink]{if}~\mycolorbox[labelBlue]{(condition)}~\mycolorbox{\textbraceleft}\\[0.5cm]
\phantom{\mycolorbox[labelPink]{if}}~\mycolorbox[labelOrange]{Code if true}\\[0.5cm]
\mycolorbox{\textbraceright}

\end{document}


The result:

You could be interested in the tcolorbox package; it offers a highly customizable \tcbox command for boxes like the ones you are using.

• Thank you kindly, but I was looking for to expand the margin of the orange box not the padding. In addition, the pink and first gray box seem to be too far away from the blue box. Can these be adjusted? – kexxcream Aug 19 '15 at 19:18
• @kexxcream What do you mean with margin? Please describe clearly what you wnat to do. – Gonzalo Medina Aug 19 '15 at 19:23
• Sorry for the confusion. By margin I mean the space between the blue box and orange box and between the bottom gray box and orange box. – kexxcream Aug 19 '15 at 19:24
• @kexxcream No proble. Now (I think) I understand. Please see my updated answer. – Gonzalo Medina Aug 19 '15 at 19:29