在 TikZ 中绘制带有边框的矩形

在 TikZ 中绘制带有边框的矩形

谁能告诉我如何绘制一个周围有黑色边框的矩形?

我希望以下 TikZ 图片中的所有矩形都具有此效果:

\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}[every node/.style = {shape          = rectangle,
                                         rounded corners,
                                         fill           = black!30!white,
                                         minimum width  = 3cm,
                                         minimum height = 1.5cm,
                                         align          = center,
                                         text           = black},
                   black edge/.style  = { -,
                                         ultra thick,
                                         black,
                                         shorten >= 2pt}]

% the nodes : possible  \newcommand*\dx{5} \newcommand*\dy{2}
\node(0;0) at (5,0) {Patients};
  \node(1;1)  at (10, 2) {Treatment $A_1$};
  \node(1;-1) at (10,-2) {Treatment $A_2$};
\foreach \j in {-1,1}
  { \draw[black edge] (0;0.east) -- (1;\j.west); }
\end{tikzpicture}
\end{document}

答案1

您可以使用draw,double=<color>,double distance = <dimen>以下every node风格:

\documentclass{article}

\setlength{\parindent}{0mm}

\usepackage{paralist}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}[every node/.style = {shape          = rectangle,
                                         rounded corners,
                                         draw,                    %% here
                                         double=red,              %% here
                                         double distance =1pt,    %% here
                                         fill           = black!30!white,
                                         minimum width  = 3cm,
                                         minimum height = 1.5cm,
                                         align          = center,                                         
                                         text           = black},
                   black edge/.style  = { -,
                                         ultra thick,
                                         black,
                                         shorten >= 2pt}]

% the nodes : possible  \newcommand*\dx{5} \newcommand*\dy{2}
\node(0;0) at (5,0) {Patients};
  \node(1;1)  at (10, 2) {Treatment $A_1$};
  \node(1;-1) at (10,-2) {Treatment $A_2$};
\foreach \j in {-1,1}
  { \draw[black edge] (0;0.east) -- (1;\j.west); }
\end{tikzpicture}

\end{document}

如果您不想要颜色,请使用简单double代替double=<color>

在此处输入图片描述

答案2

使用 PSTricks。

在此处输入图片描述

\documentclass[pstricks,border=12pt]{standalone}
\newpsobject{myrec}{psframe}
{
    border=2\pslinewidth,
    bordercolor=black,
}

\begin{document}
\begin{pspicture}[showgrid](4,3)
    \myrec[linecolor=yellow](2,1.5)
    \myrec[linecolor=white](2.5,2)(4,3)
\end{pspicture}
\end{document}

相关内容