1

I have a question regarding the complex TikZ nodes-filled solution of Qrrbrbirlbel's answer in https://tex.stackexchange.com/a/130119/238944

enter image description here

see: https://www.latex4technics.com?note=zzvqse


\documentclass[tikz,convert=false]{standalone}
\usetikzlibrary{fit}
\usetikzlibrary{shapes.multipart}

\tikzset{
  three parts left node/.style={
    every three parts node,
    name=qrr@tikz@tp@l,
    %fill=green,
    at=(qrr@tikz@tp@t.south),
    anchor=north east,
    outer sep=+0pt},
  three parts right node/.style={
    every three parts node,
    name=qrr@tikz@tp@r,
    %fill=red,
    at=(qrr@tikz@tp@t.south),
    anchor=north west,
    outer sep=+0pt},
  three parts top node/.style={
    every three parts node,
    name=qrr@tikz@tp@t,
    fill=yellow,
    outer sep=+0pt},
  three parts node/.style={
    inner sep=-.5\pgflinewidth,
    minimum size=+0pt,
    fit=(qrr@tikz@tp@l)(qrr@tikz@tp@r)(qrr@tikz@tp@t)},
  every three parts node/.style={align=center},
  three parts node after/.style={
    insert path={
      ([xshift=\pgflinewidth]   qrr@tikz@tp@t.south west) edge[three parts node after edge 1/.try] ([xshift=-\pgflinewidth]qrr@tikz@tp@t.south east)
      ([yshift=-.5\pgflinewidth]qrr@tikz@tp@l.north east) edge[three parts node after edge 2/.try] ([yshift=\pgflinewidth] qrr@tikz@tp@r.south west)}},
}
\makeatletter
\tikzset{
  three parts/.code args={#1#2#3}{%
    \pgfutil@ifnextchar[%
      {\expandafter\tikz@scan@next@command\qrr@tikz@split@nodeOpt{three parts top node}}
      {\expandafter\tikz@scan@next@command\qrr@tikz@split@nodeOpt{three parts top node}[]}#1\egroup\pgf@stop
    \pgfutil@ifnextchar[%
      {\expandafter\tikz@scan@next@command\qrr@tikz@split@nodeOpt{three parts left node}}
      {\expandafter\tikz@scan@next@command\qrr@tikz@split@nodeOpt{three parts left node}[]}#2\egroup\pgf@stop
    \pgfutil@ifnextchar[%
      {\expandafter\tikz@scan@next@command\qrr@tikz@split@nodeOpt{three parts right node}}
      {\expandafter\tikz@scan@next@command\qrr@tikz@split@nodeOpt{three parts right node}[]}#3\egroup\pgf@stop
    \tikz@scan@next@command node[three parts node/.try]{}[three parts node after]\pgf@stop
  }
}
\def\qrr@tikz@split@nodeOpt#1[#2]{node[#2,#1]\bgroup}
\makeatother
\begin{document}
\begin{tikzpicture}[three parts node/.append style={draw,rounded corners}]
\path [three parts={[blue!50!red]\textit{marriage}, 1850}{[blue]John\\Smith}{[red]Mary\\Jones}] ;
\node [ rounded corners,rectangle split,rectangle split parts=2,draw=black, rectangle split part fill={yellow,none}] at (0,1) (v){marriage\nodepart{two} John+Marry};

\end{tikzpicture}
\end{document}

When background colors are used, the solution behaves differently, i.e. the background color colorizes sharp corners, while the original split rectangle only colorized rounded corners.

How would one modify the source in order to get the background to respect the rounded corners?

1
  • One can likely repair things but I think that you'd be better off if you did those with tcolorbox, which has a better support of such things, including the mix of sharp and rounded corners.
    – user238301
    Apr 4, 2021 at 15:55

2 Answers 2

2

As user238301 suggested, you may use tcolorbox.

To avoid problem nesting tcolorbox inside a tikzpicture, you can create ordinary boxes and use them.

\documentclass[border=10pt]{standalone}
\usepackage{makecell}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usepackage[most]{tcolorbox}
\tcbuselibrary{skins,xparse}

\tcbset{
    common/.style={    
        colback = white,
        colbacktitle=yellow,
        size=fbox,
        nobeforeafter,
        center title,
        arc=1.5mm
    },
    triplebox/.style={    
        common,
        enhanced,
        sidebyside gap=7pt,
        width=3cm,
        coltitle=red,
        segmentation style=solid,
    },
}

\newtcolorbox{doulblebox}[2][]{%
    common,
    coltitle=black,
    capture=hbox,
    title = #2,
    #1}
    
\newsavebox{\boxdouble}
\newsavebox{\boxtriple}

\begin{document}
\savebox{\boxdouble}{%
    \begin{doulblebox}{marriage}
       John+Mary
    \end{doulblebox}%
    }
\savebox{\boxtriple}{%   
\tcbsidebyside[
    triplebox,
    title={{\emph{marriage}, 1850}},
    ]
    {\makecell{John\\ Smith}}
    {\makecell{Mary\\ Jones}}%
    }
\begin{tikzpicture}
\node (A) {\usebox{\boxdouble}};
\node[below=0mm of A] {\usebox{\boxtriple}};
\end{tikzpicture}
\end{document}

enter image description here

0

The problem here is that, the top node has shape rectangle, but we expect it's filled as if its two upper corners are rounded and two lower corners are remain sharp.

Currently tikz and its ("standard") libraries don't provide such shapes. If your use case is not so flexible, then replacing

three parts top node/.style={
  fill=yellow,
  ...
}

with

three parts top node/.style={
  path picture={
    \fill[yellow, rounded corners] 
      (path picture bounding box.south west) 
      -- (path picture bounding box.north west)
      -- (path picture bounding box.north east) 
      [sharp corners]-- (path picture bounding box.south east)
      -- cycle;
  },
  ...
}

would help.

PS: I learnt the use of option path picture from this answer.

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.