TikZ nested text boxes margins
To long for the comment:
- Don't nest TikZ pictures!
- One of possibilities for your node is
\documentclass[tikz, border=2mm]{standalone}
\usetikzlibrary{backgrounds,
fit,
positioning,
shapes.multipart}
\definecolor{CoreBlue}{HTML}{5b9bd5}
\definecolor{CoreOrange}{HTML}{ec7d2d}
\begin{document}
\tikzset{
base/.style = {text width=#1, align=center, text=white, outer sep=0pt},
base/.default = 17mm,
CB/.style = {base=#1, fill=CoreBlue},
CO/.style = {base=#1, fill=CoreOrange},
}
\begin{tikzpicture}[]
\node (1a) [CB] {Lorem};
\node (1b) [CO,below=0mm of 1a] {Ipsum}; \\
\scoped[on background layer]
\node (1) [CB, fit=(1a) (1b)] {};
\end{tikzpicture}
\begin{tikzpicture}[]
\node (1a) [CB] {Lorem};
\node (1b) [CO,below=0mm of 1a] {Lorem Ipsum}; \\
\scoped[on background layer]
\node (1) [CB, fit=(1a) (1b)] {};
\end{tikzpicture}
\end{document}
or
\documentclass[tikz, border=2mm]{standalone}
\usetikzlibrary{backgrounds,
fit,
positioning,
shapes.multipart}
\definecolor{CoreBlue}{HTML}{5b9bd5}
\definecolor{CoreOrange}{HTML}{ec7d2d}
\usepackage{lipsum}
\begin{document}
\tikzset{
base/.style = {text width=#1, align=center, text=white, outer sep=0pt},
base/.default = 21mm,
CB/.style = {base=#1, fill=CoreBlue},
CO/.style = {base=#1, fill=CoreOrange, font=\scriptsize},
}
\begin{tikzpicture}[]
\node (1a) [CB] {Lorem};
\node (1b) [CO,below=0mm of 1a] {Ipsum}; \\
\scoped[on background layer]
\node (1) [CB, fit=(1a) (1b)] {};
\end{tikzpicture}
\begin{tikzpicture}[]
\node (1a) [CB] {Lorem};
\node (1b) [CO,below=0mm of 1a] {\lipsum[1][1]}; \\
\scoped[on background layer]
\node (1) [CB, fit=(1a) (1b)] {};
\end{tikzpicture}
\end{document}
I suggest to draw it directly rather than nested node. If they are repeated in your code, put it in a pic
.
\documentclass[tikz, border=2mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{fit, positioning, backgrounds}
\begin{document}
\definecolor{CoreBlue}{HTML}{5b9bd5}
\definecolor{CoreOrange}{HTML}{ec7d2d}
\tikzset{
Core/.style={rectangle, draw, fill=CoreBlue, draw opacity=0, text=white},
Core2/.style={rectangle, draw, fill=CoreOrange, draw opacity=0, text=white},
}
\begin{tikzpicture}
\def\padwidth{2mm}
\node[Core2,align=center,text width=15mm] (a) {\scriptsize Ipsum};
\path ([xshift=-\padwidth]a.west) coordinate (a-l)
([xshift=\padwidth]a.east) coordinate (a-r);
\node[above=0pt of a] (b) {Lorem};
\pgfkeysgetvalue{/pgf/inner ysep}\wrapnodetbsep
\path ([yshift=-\wrapnodetbsep]a.south) coordinate (a-b);
\scoped[on background layer] \node[fit=(a)(b)(a-l)(a-r)(a-b), inner sep=0pt, fill=CoreBlue] {};
\end{tikzpicture}
\end{document}
This is a simple and quick solution/suggestion: use minimum width
,minimum height
, text width
, and align=center
. You may make a \newcomnand
to fit your need. The above Zarko's answer has some advantage over mine.
\documentclass[tikz,border=2mm]{standalone}
\usepackage{lipsum}
\begin{document}
\definecolor{CoreBlue}{HTML}{5b9bd5}
\definecolor{CoreOrange}{HTML}{ec7d2d}
\begin{tikzpicture}
\path
(0,0) node[fill=CoreBlue,minimum width=30mm,minimum height=12mm] (A) {}
(A.center)+(90:3mm) node[text=white] {Lorem}
(A.center)+(-90:2mm) node[fill=CoreOrange,text=white,minimum width=25mm,text width=20mm,align=center,font=\scriptsize]{Ipsum};
\end{tikzpicture}
\end{document}