3

I have a problem with the subfigenvironment. My two graphs created with pgfplots are too large to stay together. How can I fix that?

% Graphique
\begin{figure}
\centering
\subfloat[]{$\tau = \SI{0.1}{\second}$}
    {\begin{tikzpicture}
    \begin{axis}[title={Trajectoire de la balle dans le plan $x$-$z$}, xlabel={$x$}, ylabel={$z$},%
    legend cell align=left]

        \addplot[red,thick,each nth point={10}]
            table[x index=1,y index=3] {Data/magnus_nog_not_dt0.1s.dat};

        \legend{}
    \end{axis}
    \end{tikzpicture}} \quad

\subfloat[]{$\tau = \SI{0.001}{\second}$}
    {\begin{tikzpicture}
    \begin{axis}[title={Trajectoire de la balle dans le plan $x$-$z$}, xlabel={$x$}, ylabel={$z$},%
    legend cell align=left]

        \addplot[red,thick,each nth point={10}]
            table[x index=1,y index=3] {Data/magnus_nog_not_dt0.001s.dat};

        \legend{}
    \end{axis}
    \end{tikzpicture}}

    \caption[]{}\label{g:nognot}
\end{figure}
% Graphique

Ps: I didn't provide a MWE because you need files to compile my graphs.

  • If they don't fit, they don't so maybe make them smaller with width=0.4\textwidth ? – percusse Oct 6 '12 at 20:31
  • @percusse The graphs are small, so I don't want to make them even smaller. In addition, I want all my graphs look the same way... ;) – user17895 Oct 6 '12 at 20:40
  • Yes but what do you expect from us then? The question is not answerable because there is not much else to do. – percusse Oct 6 '12 at 20:53
  • @percusse Maybe there is some configuration of subfig that permit to the environment to exceed \textwidth... No? There is anything to do? – user17895 Oct 6 '12 at 21:00
  • @R.M. So you want the graphs side by side, no matter if they exceed the margins? If that's so, then perhaps my answer could be useful. – Gonzalo Medina Oct 6 '12 at 21:14
3

From the comments it seems that was is required is a method to have the two graphs in the same row, no matter if the margins are exceeded; one way to achieve this is using a \makebox:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows,calc,positioning}
\usepackage{subfig}
\usepackage{lipsum}

\begin{document}

\lipsum[2]
\begin{figure}
\centering
\makebox[\textwidth][c]{%
\subfloat[]{%
  \begin{tikzpicture}
  \draw (0,0) grid (7,3);
  \end{tikzpicture}}\quad
\subfloat[]{%
  \begin{tikzpicture}
  \draw (8,0) grid (15,3);
  \end{tikzpicture}}
}\\
\makebox[\textwidth][c]{%
\subfloat[]{%
  \begin{tikzpicture}
  \draw (0,0) grid (7,3);
  \end{tikzpicture}}\quad
\subfloat[]{%
  \begin{tikzpicture}
  \draw (8,0) grid (15,3);
  \end{tikzpicture}}
}
\caption[]{}
\label{g:nognot}
\end{figure}

\end{document}

enter image description here

  • That's what I need, thank you. The problem now is that it seems the \\ command is ignored: the 4 graphs are placed in a single line instead of two lines... How I can fix that? – user17895 Oct 6 '12 at 21:23
  • @R.M. Sorry but how can we anticipate four graphs in two rows when you only mentioned two graphs in your question? Anyway, the idea is the same: you can use two \makeboxes (one for each row); I'll update my answer with an example. – Gonzalo Medina Oct 6 '12 at 21:35
  • @R.M. I've updated my answer. – Gonzalo Medina Oct 6 '12 at 21:37
  • Sorry! I posted an old version of my code! – user17895 Oct 6 '12 at 21:38
  • @R.M. No problem; just make sure to provide precise information in your questions ;-) Did my updated answer helped? – Gonzalo Medina Oct 6 '12 at 21:40

Your Answer

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