1

I am struggling with putting three graphs side-by-side in one line. Every solution I could find caused errors because of the usage of axis.

\begin{tikzpicture}
    \begin{axis}[
                    domain=-10:10,
                    grid=major,
                    xmin=-10, xmax=10,
                    ymin=-10, ymax=10,
                    xlabel={x}, ylabel={y},
                    samples=1000,
                    axis y line=center,
                    axis x line=middle
                ]
        \addplot+[mark=none,color=blue] {1 * abs(x-1) + 0};
    \end{axis}
\end{tikzpicture}

\begin{tikzpicture}
    \begin{axis}[
                    domain=-10:10,
                    grid=major,
                    xmin=-10, xmax=10,
                    ymin=-10, ymax=10,
                    xlabel={x}, ylabel={y},
                    samples=1000,
                    axis y line=center,
                    axis x line=middle
                ]
        \addplot+[mark=none,color=red] {1 * abs(x-0) + 0};
    \end{axis}
\end{tikzpicture}

\begin{tikzpicture}
    \begin{axis}[
                    domain=-10:10,
                    grid=major,
                    xmin=-10, xmax=10,
                    ymin=-10, ymax=10,
                    xlabel={x}, ylabel={y},
                    samples=1000,
                    axis y line=center,
                    axis x line=middle
                ]
        \addplot+[mark=none,color=green] {1 * abs(x+1) + 0};
    \end{axis}
\end{tikzpicture}

That's how it looks at the moment.

I would like to get these three pictures side-by-side in one line including a caption for each of them + a caption for the whole figure. I tried a lot with figures and subfigures etc., but I always got error messages telling me that something is wrong because of the \begin{axis} part. This is how I would like it to look like:

https://tex.stackexchange.com/questions/120982/3-or-4-tikz-figures-side-by-side


EDIT: @martijnn2008 reply to your comment

I just tried that: Caption issue when placing figure side by side - but it doesn't work.

\begin{figure}
    \centering
    \begin{minipage}[t]{.45\textwidth}
        \centering
        \resizebox{0.2\textwidth}{!}{
            \begin{tikzpicture}
                \begin{axis}[
                        domain=-10:10,
                        grid=major,
                        xmin=-10, xmax=10,
                        ymin=-10, ymax=10,
                        xlabel={x}, ylabel={y},
                        samples=1000,
                        axis y line=center,
                        axis x line=middle
                    ]
                    \addplot+[mark=none,color=blue] {1 * abs(x-0) + 0};
                \end{axis}
            \end{tikzpicture}
        }
        \caption{A not.}
    \end{minipage}\hfill

    \begin{minipage}[t]{.45\textwidth}
        \centering
        \resizebox{0.2\textwidth}{!}{
            \begin{tikzpicture}
                \begin{axis}[
                        domain=-10:10,
                        grid=major,
                        xmin=-10, xmax=10,
                        ymin=-10, ymax=10,
                        xlabel={x}, ylabel={y},
                        samples=1000,
                        axis y line=center,
                        axis x line=middle
                    ]
                    \addplot+[mark=none,color=blue] {1 * abs(x-0) + 0};
                \end{axis}
            \end{tikzpicture}
        }
        \caption{A caption.}
    \end{minipage}
    \caption{Lorem Ipsum dolor sit atmet.}
\end{figure}

As you can see in the image, the two graphs are still not in one row. But we have captions now.

enter image description here

1

Many thanks to @martijnn2008 and @cmhughes! Here is the solution:

\begin{figure}
    \centering
    \begin{minipage}[t]{.50\textwidth}
        \centering
            \begin{tikzpicture}
                \begin{axis}[
                        domain=-10:10,
                        grid=major,
                        xmin=-10, xmax=10,
                        ymin=-10, ymax=10,
                        xlabel={x}, ylabel={y},
                        samples=1000,
                        axis y line=center,
                        axis x line=middle
                    ]
                    \addplot+[mark=none,color=blue] {1 * abs(x-0) + 0};
                \end{axis}
            \end{tikzpicture}

        \caption{$h=0$}
    \end{minipage}\hfill
    \begin{minipage}[t]{.50\textwidth}
        \centering
            \begin{tikzpicture}
                \begin{axis}[
                        domain=-10:10,
                        grid=major,
                        xmin=-10, xmax=10,
                        ymin=-10, ymax=10,
                        xlabel={x}, ylabel={y},
                        samples=1000,
                        axis y line=center,
                        axis x line=middle
                    ]
                    \addplot+[mark=none,color=red] {1 * abs(x-1) + 0};
                \end{axis}
            \end{tikzpicture}
        \caption{$h=1$}
    \end{minipage}
    \caption{$\forall a, h, k \in \mathbb{R}, f(x) = a \mid x-h \mid + k$}
\end{figure}

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.