以虚线/点线样式绘制分割矩形的各个部分

以虚线/点线样式绘制分割矩形的各个部分

我尝试以虚线或点线样式绘制分割矩形的各个部分。因此,我需要以下代码

\node[draw,rectangle split,rectangle split parts=2,rectangle split horizontal]
  {foo \nodepart[text width=2cm]{second} bar};

生成如下图像:

在此处输入图片描述

虚线/点线部分应该看起来统一,即图片中虚线的不同长度是由于我的绘画技巧不好造成的;-)

我也想对垂直分割矩形使用相同的效果。有什么想法吗?

答案1

节点建立后绘制整个边框:

\documentclass[tikz,border=2mm]{standalone}

\usetikzlibrary{shapes.multipart, calc}

\begin{document}

\begin{tikzpicture}

\node[rectangle split,rectangle split parts=2, rectangle split horizontal,
    align=center,
    alias=othername, 
    append after command={\pgfextra
        \draw ($(othername.one split south)!.25!(othername.south east)$)-|(othername.west)|-($(othername.one split north)!.25!(othername.north east)$);
        \draw ($(othername.one split south)!.75!(othername.south east)$)-|(othername.east)|-($(othername.one split north)!.75!(othername.north east)$);
        \draw[dashed] ($(othername.one split south)!.25!(othername.south east)$)--($(othername.one split south)!.75!(othername.south east)$);
        \draw[dashed] ($(othername.one split north)!.25!(othername.north east)$)--($(othername.one split north)!.75!(othername.north east)$);
        \draw (othername.one split north)--(othername.one split south);
    \endpgfextra} ]
  {foo \nodepart[text width=2cm, draw=none]{second} bar};

\end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

尝试用白色虚线覆盖多部分节点的第二部分:

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{shapes.multipart}

\begin{document}
    \begin{tikzpicture}[
node distance = 0pt,
  mpnh/.style = {% multi part node horisontal
        rectangle split, rectangle split parts=2,
        rectangle split horizontal, 
        draw, outer sep=0pt, align=center}
                        ]
\node (mpnh) [mpnh]
    {foo 
    \nodepart[text width=2cm]{second} bar};
\draw[white, semithick, dashed] (mpnh.two north)+(-0.5,0) -- ++ (.5,0)
                                (mpnh.two south)+(-0.5,0) -- ++ (.5,0);
    \end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容