2

The following code makes the legend over the plot (and the size of the plot is too small):

\documentclass{article}
\usepackage[margin=2.5cm]{geometry}
\usepackage{tikz}
\usetikzlibrary{arrows,arrows.meta,
                backgrounds, bending,
                calc, chains,
                %decorations.pathmorphing,
                fit,
                %petri,
                positioning,
                trees,
                quotes,
                shapes.misc}

\definecolor{darkblue}{RGB}{31,22,70}
\definecolor{darkblue2}{RGB}{21,126,251}
\usepackage{graphicx}
\usepackage{float}
\usepackage{caption}
\usepackage{subcaption}
\usetikzlibrary{shapes.geometric}
\usetikzlibrary{shapes.geometric,intersections,calc}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\usepackage{textcomp}
\usepackage{wrapfig}


\usepackage{siunitx}
\begin{document}
\begin{wrapfigure}{r}{0.5\textwidth}
                \begin{tikzpicture}
                    \begin{axis}[
                        title={x},
                        xlabel={xx},
                        ylabel={Temps [$Secondes$]},
                        xmin=0, xmax=1000,
                        ymin=0, ymax=25,
                        xtick={20,100,200,500,1000},
                        ytick={0,5,10,15,20,25},
                        legend pos=north west,
                        ymajorgrids=true,
                        grid style=dashed,
                    ]    
                \addplot[
                  color=red,
                  mark=halfcircle*,
                ]
                coordinates {(0,0) (5,5)(50,7)(100,9)(200,9)(500,9.5)(750,9)(1000,9.5)};
                \legend{xx}

                \addplot[
                  color=cyan,
                  mark=halfcircle*,
                ]
                coordinates {(0,0) (5,5)(50,12)(100,25)(200,20)(500,15)(750,20)(1000,27)};
                \addlegendimage{/pgfplots/refstyle=Hplot}\addlegendentry{xx}
               \end{axis}
                \end{tikzpicture}
              \caption{A gull}
            \end{wrapfigure}
\end{document}

How can I fix that? Thanks

2

You can scale your graph through the axis options width=<width> and height=<height>. Other possibility is to use a \resizebox {\textwidth}{\height} inside the wrapfigure. Keep in mind that \resizebox scales the font size inside your tikzpicture, too. Nevertheless, if you use these solutions with wrapfigure you have to take care of its width as well.

You can tune the position of the legend with legend style={at={(<x>,<y>)},anchor=<name>}

Output wrapfigure and axis options:

enter image description here

Code:

\documentclass{article}
\usepackage[margin=2.5cm]{geometry}
\usepackage{tikz}
\usetikzlibrary{arrows,arrows.meta,
                backgrounds, bending,
                calc, chains,
                %decorations.pathmorphing,
                fit,
                %petri,
                positioning,
                trees,
                quotes,
                shapes.misc}

\definecolor{darkblue}{RGB}{31,22,70}
\definecolor{darkblue2}{RGB}{21,126,251}
\usepackage{graphicx}
\usepackage{float}
\usepackage{caption}
\usepackage{subcaption}
\usetikzlibrary{shapes.geometric}
\usetikzlibrary{shapes.geometric,intersections,calc}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\usepackage{textcomp}
\usepackage{wrapfig}


\usepackage{siunitx}
\begin{document}
\begin{wrapfigure}{r}{1.0\textwidth}
                \begin{tikzpicture}
                    \begin{axis}[
                        width=\textwidth,
                        height=\axisdefaultheight,
                        title={x},
                        xlabel={xx},
                        ylabel={Temps [$Secondes$]},
                        xmin=0, xmax=1000,
                        ymin=0, ymax=25,
                        xtick={20,100,200,500,1000},
                        ytick={0,5,10,15,20,25},
%                        legend pos=north west,
                        legend style={at={(1.05,1.0)},anchor=north}, % legend pos=outer north east,
                        ymajorgrids=true,
                        grid style=dashed,
                    ]    
                \addplot[
                  color=red,
                  mark=halfcircle*,
                ]
                coordinates {(0,0) (5,5)(50,7)(100,9)(200,9)(500,9.5)(750,9)(1000,9.5)};
                \legend{xx}

                \addplot[
                  color=cyan,
                  mark=halfcircle*,
                ]
                coordinates {(0,0) (5,5)(50,12)(100,25)(200,20)(500,15)(750,20)(1000,27)};
                \addlegendimage{/pgfplots/refstyle=Hplot}\addlegendentry{xx}
               \end{axis}
                \end{tikzpicture}
              \caption{A gull}
            \end{wrapfigure}
\end{document}

Output wrapfigure and resizebox:

enter image description here

Code:

\documentclass{article}
\usepackage[margin=2.5cm]{geometry}
\usepackage{tikz}
\usetikzlibrary{arrows,arrows.meta,
                backgrounds, bending,
                calc, chains,
                %decorations.pathmorphing,
                fit,
                %petri,
                positioning,
                trees,
                quotes,
                shapes.misc}

\definecolor{darkblue}{RGB}{31,22,70}
\definecolor{darkblue2}{RGB}{21,126,251}
\usepackage{graphicx}
\usepackage{float}
\usepackage{caption}
\usepackage{subcaption}
\usetikzlibrary{shapes.geometric}
\usetikzlibrary{shapes.geometric,intersections,calc}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\usepackage{textcomp}
\usepackage{wrapfig}


\usepackage{siunitx}
\begin{document}
\begin{wrapfigure}{r}{1.0\textwidth}
                \resizebox {\textwidth}{!} {
                \begin{tikzpicture}
                    \begin{axis}[
                      %  width=\textwidth,
                       % height=\axisdefaultheight,
                        title={x},
                        xlabel={xx},
                        ylabel={Temps [$Secondes$]},
                        xmin=0, xmax=1000,
                        ymin=0, ymax=25,
                        xtick={20,100,200,500,1000},
                        ytick={0,5,10,15,20,25},
                      % legend pos=north west,
                        legend style={at={(1.15,1.0)},anchor=north}, % legend pos=outer north east,
                        ymajorgrids=true,
                        grid style=dashed,
                    ]    
                \addplot[
                  color=red,
                  mark=halfcircle*,
                ]
                coordinates {(0,0) (5,5)(50,7)(100,9)(200,9)(500,9.5)(750,9)(1000,9.5)};
                \legend{xx}

                \addplot[
                  color=cyan,
                  mark=halfcircle*,
                ]
                coordinates {(0,0) (5,5)(50,12)(100,25)(200,20)(500,15)(750,20)(1000,27)};
                \addlegendimage{/pgfplots/refstyle=Hplot}\addlegendentry{xx}
               \end{axis}
                \end{tikzpicture}
            }
              \caption{A gull}
            \end{wrapfigure}
\end{document}
  • 1
    Nice, thanks a lot :) – Warok Jul 1 '19 at 9:18

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.