在下面的 tikz MWE 中我使用 fit 库绘制一个红色框:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{fit}
\begin{document}
\begin{tikzpicture}
\node (a) {A};
\node [above right=of a] (b) {B};
\node [right=of a] (c) {C};
\node [draw=red, fit=(a) (b)] {};
\end{tikzpicture}
\end{document}
不幸的是,这个拟合框包含 C 节点。是否可以使用拟合在 A 和 B 周围绘制一个框,并使用非垂直/水平线或使用多条“阶梯”式垂直/水平线来排除 C 来包含 C?
答案1
如果我们可以绘制它,这里有一个不太好的(我第一次使用它)带有hobby
库的示例:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{fit,positioning,hobby}
\begin{document}
\begin{tikzpicture}
\node (a) {A};
\node [above right=of a] (b) {B};
\node [right=of a] (c) {C};
\draw[thick, red] ([shift={(-3mm,-3mm)}]a.south west) to[curve through={(a.south east) .. (b.south east) .. ([shift={(+3mm,+3mm)}]b.north east)..(b.north west)..(a.north west)}] ([shift={(-3mm,-3mm)}]a.south west);
\end{tikzpicture}
\end{document}
hobby
更新:阅读文档后,有一个更好的更新:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{fit,positioning,hobby}
\begin{document}
\begin{tikzpicture}
\node (a) {A};
\node [above right=of a] (b) {B};
\node [right=of a] (c) {C};
\draw[thick, red] ([shift={(-3mm,-3mm)}]a.south west) to[closed, curve through={(a.south east) .. (b.south east) .. ([shift={(+3mm,+3mm)}]b.north east)..(b.north west)..(a.north west)}] cycle;
\end{tikzpicture}
\end{document}
答案2
rotate fit
一个选项是像这样使用:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{fit,positioning,calc}
\begin{document}
\begin{tikzpicture}
\node (a) {A};
\node [above right=of a] (b) {B};
\node [right=of a] (c) {C};
\node [draw=red, rotate fit=45, fit=(a) (b)] {};
\end{tikzpicture}
\end{document}