0

I am trying to place two tikz axes side by side. I currently encapsulate each in a subfigure, but it seems that there are too much white space around the tikz figures that I can barely see the pictures even if I set the width to 0.5\tetxwidth. I have the following code, would appreciate any help!

\begin{figure*}
    \begin{center}
    \begin{subfigure}[t]{0.5\textwidth}
        \centering
    \begin{tikzpicture}
        \begin{axis}[
        enlargelimits=false,
        width=0.5\textwidth,
        axis lines=middle,xmin=-1.2,xmax=1.2,ymin=-1.2,ymax=1.2, 
        xlabel=$\scriptstyle x$,ylabel=$\scriptstyle y$, 
        yticklabels=\empty,
        xticklabels=\empty,
        axis equal]
        \begin{scope}
            \clip (0, 0) rectangle (1, 1);
            \clip (0, 0)--(0.33, 1)--(0, 1)--cycle;
            \fill[yellow, opacity=0.6] (0, 0) circle (1);
        \end{scope}
        \addplot+[name path = gaussian, no marks,
        domain=-1.5:1.5,samples=15] {3*x};
        \draw[name path = line] (axis cs:0,0) circle [blue, radius=1];
        \end{axis}
    \end{tikzpicture}
    \end{subfigure}\hfill
    \begin{subfigure}[t]{.5\textwidth}
        \centering
        \begin{tikzpicture}
            \begin{axis}[
            enlargelimits=false,
            width=0.5\textwidth,
            axis lines=middle,xmin=-1.2,xmax=1.2,ymin=-1.2,ymax=1.2, 
            xlabel=$\scriptstyle x$,ylabel=$\scriptstyle y$, 
            yticklabels=\empty,
            xticklabels=\empty,
            axis equal
            ]
            \begin{scope}
                \clip (0, 0) rectangle (1, 1);
                \clip (0, 0)--(0.33, 1)--(0, 1)--cycle;
                \fill[yellow, opacity=0.6] (0, 0) circle (1);
            \end{scope}
            \addplot+[name path = gaussian, no marks,
            domain=-1.5:1.5,samples=15] {3*x};
            \draw[name path = line] (axis cs:0,0) circle [blue, radius=1];
            \end{axis}
        \end{tikzpicture}
        \end{subfigure}
    \end{center}
    \end{figure*}

1 Answer 1

0

Leave out width=0.5\textwidth.
Please post a minimal example with your preamble because I invented it and maybe not the same in your actual document.

\documentclass[margin=2in]{book}

\usepackage{tikz}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}
\usepackage{caption}
\usepackage{subcaption}

\begin{document}
\begin{figure*}
    \begin{center}
    \begin{subfigure}[t]{0.4\linewidth}
        \centering
    \begin{tikzpicture}
        \begin{axis}[
        enlargelimits=false,
%         width=0.5\textwidth,
        axis 

    lines=middle,xmin=-1.2,xmax=1.2,ymin=-1.2,ymax=1.2, 
        xlabel=$\scriptstyle x$,ylabel=$\scriptstyle y$, 
        yticklabels=\empty,
        xticklabels=\empty,
        axis equal]
        \begin{scope}
            \clip (0, 0) rectangle (1, 1);
            \clip (0, 0)--(0.33, 1)--(0, 1)--cycle;
            \fill[yellow, opacity=0.6] (0, 0) circle (1);
        \end{scope}
        \addplot+[name path = gaussian, no marks,
        domain=-1.5:1.5,samples=15] {3*x};
        \draw[name path = line] (axis cs:0,0) circle [blue, radius=1];
        \end{axis}
    \end{tikzpicture}
    \end{subfigure}\hfill
    \begin{subfigure}[t]{.4\linewidth}
        \centering
        \begin{tikzpicture}
            \begin{axis}[
            enlargelimits=false,
        %   width=0.5\textwidth,
            axis lines=middle,xmin=-1.2,xmax=1.2,ymin=-1.2,ymax=1.2, 
            xlabel=$\scriptstyle x$,ylabel=$\scriptstyle y$, 
            yticklabels=\empty,
            xticklabels=\empty,
            axis equal
            ]
            \begin{scope}
                \clip (0, 0) rectangle (1, 1);
                \clip (0, 0)--(0.33, 1)--(0, 1)--cycle;
                \fill[yellow, opacity=0.6] (0, 0) circle (1);
            \end{scope}
            \addplot+[name path = gaussian, no marks,
            domain=-1.5:1.5,samples=15] {3*x};
            \draw[name path = line] (axis cs:0,0) circle [blue, radius=1];
            \end{axis}
        \end{tikzpicture}
        \end{subfigure}
    \end{center}
    \end{figure*}
\end{document}

enter image description here

2
  • This works perfectly for me. Thank you! Nov 8, 2021 at 8:33
  • @georgezywang You're welcome, thank you for accepting my answer.
    – CarLaTeX
    Nov 8, 2021 at 10:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .