我如何在 tikz 中绘制此图片。我确实尝试使用 hobby(tikz 库),但我无法在其中放置任何文本:
我已经尝试过这个代码:
\documentclass{article}
\usepackage[latin1]{inputenc}
\usepackage{tikz}
\usetikzlibrary{hobby}
\begin{document}
\pagestyle{empty}
\begin{tikzpicture}
\path[draw,use Hobby shortcut,closed=true, fill=yellow!80]
(0,0) .. (4,0) .. (4,4) .. (2.5,2) .. (0,0);
\path[draw,use Hobby shortcut,closed=true, fill=blue!20]
(1,0.5) .. (3.5,0.5) .. (3.5,2.5) .. (2.5,1.5) .. (1, 0.5);
\end{tikzpicture}
\end{document}
这给了我以下信息:
答案1
使用标签定义曲线的坐标:
\documentclass[border=3.141592]{standalone}
\usepackage{tikz}
\usetikzlibrary{backgrounds,
hobby}
\begin{document}
\begin{tikzpicture}[
every label/.append style = {inner sep=2ex, font=\sffamily\bfseries}
]
\path (3.5,2.5) coordinate[label=above right:A] (a)
(2.5,1.5) coordinate[label=below right:B] (b);
%
\scoped[on background layer]
{
\path[draw,use Hobby shortcut,closed=true, fill=yellow!80]
(0,0) .. (4,0) .. (4,4) .. (2.5,2) .. (0,0);
\path[draw,use Hobby shortcut,closed=true, fill=blue!20]
(1,0.5) .. (3.5,0.5) .. (a) .. (b) .. (1, 0.5);
}
\end{tikzpicture}
\end{document}
答案2
\documentclass{article}
\usepackage[latin1]{inputenc}
\usepackage{tikz}
\usetikzlibrary{hobby,calc}
\begin{document}
\pagestyle{empty}
\begin{tikzpicture}
\path[draw,use Hobby shortcut,closed=true, fill=yellow!80]
(0,0) .. (4,0) .. (4,4) .. (2.5,2) .. (0,0);
\path[draw,use Hobby shortcut,closed=true, fill=blue!20]
(1,0.5) .. (3.5,0.5) .. (3.5,2.5) .. (2.5,1.5) .. (1, 0.5);
\node at ($(current bounding box)+(1cm,2cm)$) {Q};
\end{tikzpicture}
\end{document}
使用
\node at ($(current bounding box.center)+(0cm,0cm)$) {Q};