0

I need to put a tikzpicture inside a node but the tikzpicture in the wrong position of node labels. Please fix for me.

enter image description here

\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}
  • 7
    Yes, this is one of the reasons why one should not nest tikzpictures. Putting a tikzpicture in a node of another tikzpicture is not supported. –  Mar 09 '20 at 06:33
  • See https://tex.stackexchange.com/q/47377. –  Mar 09 '20 at 06:40

1 Answers1

1

For this particular question I think you want the tcolorbox package:

enter image description here

Here is you slightly modified 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}