tikz 中具有给定坐标的矩形节点

tikz 中具有给定坐标的矩形节点

如何制作具有给定左下角和右上角、给定边框颜色和填充颜色的 tikz 矩形节点?我知道这似乎是一个基本问题,但我在手册中找不到示例!我试过这个:

\documentclass[tikz,border=0.25cm]{standalone}
\begin{document}
\begin{tikzpicture}
\node [shape=rectangle, thin, color=red, fill=red, fill opacity=0.4, minimum width=0.5599999999999998, minimum height=3.3999999999999995, above right] (A) at (1.4000000000000001, -3.0999999999999996) {};
\end{tikzpicture}
\end{document}

答案1

您可以使用该fit库:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{fit}

\begin{document}

\begin{tikzpicture}[
myrect/.style={
  rectangle,
  draw,
  inner sep=0pt,
  fit=#1}
]
\coordinate (A) at (2,3);
\coordinate (B) at (-3,4);
\coordinate (C) at (0,2);
\coordinate (D) at (-5,6);
\coordinate (E) at (5,-2);
\node[myrect={(A) (B)}] {}; 
\node[myrect={(C) (D)},draw=cyan,rounded corners] {}; 
\node[myrect={(A) (E)},draw=cyan,fill=orange,line width=2pt] {}; 
\foreach \Coord in {A,B,C,D,E}
  \node[circle,fill,inner sep=1.5pt,label=\Coord] at (\Coord) {};
\end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容