2

I want a tikzpicture inside a tcolorbox. But for some reason it floats outside the box. How can I center the image correctly?

enter image description here

\documentclass[10pt, a4paper, twoside, titlepage, openbib]{article}

    \usepackage{tikz}
        %Tikz is een library die toestaat om tekeningen te maken
        \usetikzlibrary{shapes}
            %Shapes
        \usetikzlibrary{arrows}
            %Arrows
        \usetikzlibrary{calc}
            %Calculation
        \usetikzlibrary{decorations}
            %Decorations
        \usetikzlibrary{backgrounds}
            %Backgrounds
        \usetikzlibrary{fit}
            %
        \usetikzlibrary{positioning}
            %
        \usetikzlibrary{chains}
            %
    \usepackage[europeanresistors,americaninductors]{circuitikz}
    \usepackage{tcolorbox}
        %http://mirror.unl.edu/ctan/macros/latex/contrib/tcolorbox/tcolorbox.pdf
        \tcbuselibrary{listings}
        \tcbuselibrary{theorems}

\begin{document}

%---Image--------------------------------------------------------------------------------------------   
\begin{figure*}[ht!] %het blokschema
    \centering
    \begin{tcolorbox}[colback=white]
    \begin{tikzpicture}[node distance = 0.2cm, auto]
        \begin{circuitikz}
            \draw
                (8.5,-1.) node[draw,minimum width=2cm,minimum height=2.4cm] (load) {Load}
                    ($(load.west)!0.75!(load.north west)$) coordinate (la)
                    ($(load.west)!0.75!(load.south west)$) coordinate (lb)
                (1,3) node[spdt,xscale=1, yscale=1,anchor=in] (myspdt1) {}
                (4,3) node[spdt,xscale=-1,yscale=1,anchor=in] (myspdt2) {}
                (5,0)   node[ground, yscale=1]{}
                        to[full led]        (5,3)
                        to(myspdt2.in)
                (0,0)   node[ground]{}
                        to[vsourcesin]      (0,3)
                        to(myspdt1.in)
                (0,2) node[right]{$V_{s}(t)$}
                (myspdt1.out 1) -- (myspdt2.out 1)
                (myspdt1.out 2) -- (myspdt2.out 2);
        \end{circuitikz}
    \end{tikzpicture}
    \end{tcolorbox}   
        \caption{Het eerste probleem} 
        \label{fig:Het eerste probleem} 
\end{figure*}
%---Image--------------------------------------------------------------------------------------------

\end{document}
2

The problem is the nesting of circuitikz environment within tikzpicture, which is not recommended.

Remove the outer tikzpicture environment and change the vertical position of the Load frame 'slightly':

\documentclass[10pt, a4paper, twoside, titlepage, openbib]{article}

    \usepackage{tikz}
        %Tikz is een library die toestaat om tekeningen te maken
        \usetikzlibrary{shapes}
            %Shapes
        \usetikzlibrary{arrows}
            %Arrows
        \usetikzlibrary{calc}
            %Calculation
        \usetikzlibrary{decorations}
            %Decorations
        \usetikzlibrary{backgrounds}
            %Backgrounds
        \usetikzlibrary{fit}
            %
        \usetikzlibrary{positioning}
            %
        \usetikzlibrary{chains}
            %
    \usepackage[europeanresistors,americaninductors]{circuitikz}
    \usepackage[most]{tcolorbox}
    % http://mirror.unl.edu/ctan/macros/latex/contrib/tcolorbox/tcolorbox.pdf
    \tcbuselibrary{listings}
    \tcbuselibrary{theorems}

\begin{document}

%---Image--------------------------------------------------------------------------------------------   
\begin{figure*}[ht!] %het blokschema
    \centering
    \begin{tcolorbox}[colback=white]
        \begin{circuitikz}[node distance = 0.2cm, auto]
            \draw
                (8.5,2) node[draw,minimum width=2cm,minimum height=2.4cm] (load) {Load}
                    ($(load.west)!0.75!(load.north west)$) coordinate (la)
                    ($(load.west)!0.75!(load.south west)$) coordinate (lb)
                (1,3) node[spdt,xscale=1, yscale=1,anchor=in] (myspdt1) {}
                (4,3) node[spdt,xscale=-1,yscale=1,anchor=in] (myspdt2) {}
                (5,0)   node[ground, yscale=1]{}
                        to[full led]        (5,3)
                        to(myspdt2.in)
                (0,0)   node[ground]{}
                        to[vsourcesin]      (0,3)
                        to(myspdt1.in)
                (0,2) node[right]{$V_{s}(t)$}
                (myspdt1.out 1) -- (myspdt2.out 1)
                (myspdt1.out 2) -- (myspdt2.out 2);
        \end{circuitikz}
    \end{tcolorbox}   
    \caption{Het eerste probleem} 
    \label{fig:Het eerste probleem} 
\end{figure*}
%---Image--------------------------------------------------------------------------------------------

\end{document}

enter image description here

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.