我需要将 tikzpicture 放在节点内,但 tikzpicture 位于节点标签的错误位置。请帮我修复。
\documentclass[12pt,a4paper,oneside]{book}
\usepackage{amsmath,lipsum}
\usepackage[top=2cm,bottom=2cm,left=2cm,right=2cm]{geometry}
\usepackage{tikz,tkz-euclide}
\usetkzobj{all}
\begin{document}
\begin{tikzpicture}[line cap=round,line join=round,x=1.0cm,y=1.0cm,>=stealth,scale=1]
\tkzDefPoints{0/0/O,-1/2/C,3/1/A}
\coordinate (B) at ($(A)+(C)$);
\draw[->] (-2.5,0) --(3.5,0) node[above]{$x$};
\draw[->] (0,-1) --(0,3.5) node[right]{$y$};
\fill (O) node[shift={(-130:2ex)}]{$O$} circle(1pt);
\fill (A) node[shift={(0:4ex)}]{$A(3;1)$} circle(1pt);
\fill (C) node[shift={(0:-5ex)}]{$C(-1;2)$} circle(1pt);
\fill (B) node[shift={(40:2ex)}]{$B$} circle(1pt);
\tkzDrawPolygon[fill=gray!80,opacity=0.3](O,A,B,C)
\end{tikzpicture}
\begin{tikzpicture}
\node (cau)[below=1mm,inner sep=10pt,draw=violet,rounded corners=1mm]
{
\begin{minipage}{0.8\textwidth}
\lipsum[1]\\
\begin{tikzpicture}[line cap=round,line join=round,x=1.0cm,y=1.0cm,>=stealth,scale=1]
\tkzDefPoints{0/0/O,-1/2/C,3/1/A}
\coordinate (B) at ($(A)+(C)$);
\draw[->] (-2.5,0) --(3.5,0) node[above]{$x$};
\draw[->] (0,-1) --(0,3.5) node[right]{$y$};
\fill (O) node[shift={(-130:2ex)}]{$O$} circle(1pt);
\fill (A) node[shift={(0:4ex)}]{$A(3;1)$} circle(1pt);
\fill (C) node[shift={(0:-5ex)}]{$C(-1;2)$} circle(1pt);
\fill (B) node[shift={(40:2ex)}]{$B$} circle(1pt);
\tkzDrawPolygon[fill=gray!80,opacity=0.3](O,A,B,C)
\end{tikzpicture}
\end{minipage}
};
\end{tikzpicture}
\end{document}
答案1
对于这个问题,我认为你想彩色盒子包裹:
以下是稍微修改过的 MWE:
\documentclass[12pt,a4paper,oneside]{book}
\usepackage{amsmath,lipsum}
\usepackage[top=2cm,bottom=2cm,left=2cm,right=2cm]{geometry}
\usepackage{tikz,tkz-euclide}
\usepackage{tcolorbox}
\usetkzobj{all}
\begin{document}
\begin{tikzpicture}[line cap=round,line join=round,x=1.0cm,y=1.0cm,>=stealth,scale=1]
\tkzDefPoints{0/0/O,-1/2/C,3/1/A}
\coordinate (B) at ($(A)+(C)$);
\draw[->] (-2.5,0) --(3.5,0) node[above]{$x$};
\draw[->] (0,-1) --(0,3.5) node[right]{$y$};
\fill (O) node[shift={(-130:2ex)}]{$O$} circle(1pt);
\fill (A) node[shift={(0:4ex)}]{$A(3;1)$} circle(1pt);
\fill (C) node[shift={(0:-5ex)}]{$C(-1;2)$} circle(1pt);
\fill (B) node[shift={(40:2ex)}]{$B$} circle(1pt);
\tkzDrawPolygon[fill=gray!80,opacity=0.3](O,A,B,C)
\end{tikzpicture}
\begin{tcolorbox}[colframe=violet,rounded corners, width=0.8\textwidth]
\lipsum[1]\\
\begin{tikzpicture}[line cap=round,line join=round,x=1.0cm,y=1.0cm,>=stealth,scale=1]
\tkzDefPoints{0/0/O,-1/2/C,3/1/A}
\coordinate (B) at ($(A)+(C)$);
\draw[->] (-2.5,0) --(3.5,0) node[above]{$x$};
\draw[->] (0,-1) --(0,3.5) node[right]{$y$};
\fill (O) node[shift={(-130:2ex)}]{$O$} circle(1pt);
\fill (A) node[shift={(0:4ex)}]{$A(3;1)$} circle(1pt);
\fill (C) node[shift={(0:-5ex)}]{$C(-1;2)$} circle(1pt);
\fill (B) node[shift={(40:2ex)}]{$B$} circle(1pt);
\tkzDrawPolygon[fill=gray!80,opacity=0.3](O,A,B,C)
\end{tikzpicture}
\end{tcolorbox}
\end{document}