The following MWE constructs some kind of custom node (combination of two nodes) to get the desired result:
\documentclass{article}
\usepackage{tikz}
\tikzset{
every node/.style={fill=blue!30,draw,rectangle,inner sep=0pt,outer sep=0pt},
innerRectangle/.style={minimum height=2cm, minimum width=2cm},
outerRectangle/.style={fill=red!50,minimum height=3cm, minimum width=2.5cm},
}
\begin{document}
\begin{tikzpicture}
\node[outerRectangle] (o) {};
\node[innerRectangle,anchor=east] (i) at (o.east) {};
\end{tikzpicture}
\end{document}
The output is:
Question: Is there an easier way, e.g. a single node definition with custom inner seps for one or each side?
Update 1 (triggered by Ignasi's answer):
I did not mention that I would like to insert text into the inner node and that this text should honor the custom inner sep. The following MWE (based on Ignasi's answer, I just added the lipsum
package and replaced minimum width
by text width
) demonstrates the problem:
\documentclass{article}
\usepackage{lipsum}
\usepackage{tikz}
\usetikzlibrary{positioning}
\tikzset{
every node/.style={
fill=blue!30,
draw,
rectangle,
inner sep=0pt,outer sep=0pt
},
outerRectangle/.style={%
fill=red!50,
minimum height=3cm,
text width=5cm,
},%
innerRectangle/.style={%
path picture={%
\draw[fill=blue!30] ([yshift=-#1]path picture bounding box.north east)
-|([xshift=#1]path picture bounding box.west)
|-([yshift=#1]path picture bounding box.south east)
--cycle;}},
innerRectangle/.default=5mm%<- when called without parameter
}
\begin{document}
\begin{tikzpicture}
\node[outerRectangle, innerRectangle] (x) {\lipsum[1]};
\end{tikzpicture}
\end{document}
Screenshot of the box the update produces:
Best Answer
You can use
path picture
option to add an inner filled region to your node:Update:
This is an alternative solution which I hope solves the problem of which area to use for text. Previous solution used a node over which an
inner border
was drawn. In this case aninner node
is used for text and an extra path is added as outer border. This outer border is defined with afit
node. Although this outer node has its own name for reference I don't know how to use it for positioning, so the positioning is only done with inner node.