Seite 1 von 1

Legende unten mittig einfügen

Verfasst: Mo 31. Okt 2016, 13:17
von Vaschan
Hallo zusammen,
\documentclass[a4paper]{article}

%% Language and font encodings
\usepackage[english]{babel}
\usepackage[utf8x]{inputenc}
\usepackage[T1]{fontenc}

%% Sets page size and margins
\usepackage[a4paper,top=3cm,bottom=2cm,left=3cm,right=3cm,marginparwidth=1.75cm]{geometry}

%% Useful packages
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{pgfplots}
\pgfplotsset{width=7cm,compat=1.3}


\begin{document}

\begin{tikzpicture}
\begin{axis}[legend pos=south west]
\addplot coordinates {(0,0) (1,1)};
\addplot coordinates {(0,1) (1,2)};
\addplot coordinates {(0,2) (1,3)};
\legend{$l_1$,$l_2$,$l_3$}
\end{axis}
\end{tikzpicture}


\end{document}
das Programm stammt aus der Doku. Ich hätte jetzt gerne die Legende unten mittig statt auf der linken Seite. Nur South geht leider nicht.

Jemand eine Idee? Vielen Dank

Verfasst: Mo 31. Okt 2016, 14:20
von Gast
In der [d]pgfplots[/d]-Doku ist auch angeben, dass das letztlich nur eine Abkürzung ist. Man kann also fehlende Platzierungsoptionen auch einfach durch die entsprechenden Stil-Erweiterungen bilden:
\documentclass[a4paper]{article}

%% Language and font encodings
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}% utf8x nur wenn unbedingt notwendig, weil es gerne Probleme macht!
\usepackage[T1]{fontenc}

%% Sets page size and margins
\usepackage[a4paper,top=3cm,bottom=2cm,left=3cm,right=3cm,marginparwidth=1.75cm]{geometry}

%% Useful packages
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{pgfplots}
\pgfplotsset{width=7cm,compat=1.3}


\begin{document}

\begin{tikzpicture}
\begin{axis}[every axis legend/.append style={at={(0.5,0)},anchor=south}]
\addplot coordinates {(0,0) (1,1)};
\addplot coordinates {(0,1) (1,2)};
\addplot coordinates {(0,2) (1,3)};
\legend{$l_1$,$l_2$,$l_3$}
\end{axis}
\end{tikzpicture}


\end{document}
BTW: 1.3 ist schon reichlich alt!!! Wir sind inzwischen bei Version 1.14 angelangt. Overleaf hat immerhin bereits 1.12. Wenn du wirklich kein neues pgfplots hast, dann solltest du updaten!

Verfasst: Mo 31. Okt 2016, 14:23
von esdd
Soll die Legende im Diagramm sein?
\begin{axis}[legend style={anchor=south,at={(.5,.02)}}]
Oder unterhalb, wie beispielsweise mit
\begin{axis}[legend style={anchor=north,at={([yshift=-1em]xticklabel cs:.5)}}]
Das Paket graphicx wird übrigens sowieso geladen, wenn Du pgfplots lädst. Und warum gibst Du mit 1.3 eine so alte Version für pgfplots an? Aktuell ist 1.14.

Verfasst: Mo 31. Okt 2016, 17:23
von Vaschan
Besten Dank! Hat geklappt.

Danke auch für den Hinweis mit der Version.
Ich habe das Beispiel einfach aus der Doku, in der stand, diese Zeile müsse in die Präambel. Aber dann werde ich das einfach rauslassen.

Verfasst: Mo 31. Okt 2016, 17:26
von esdd
Bitte die Zeile nicht einfach rauslassen, sondern compat entweder auf newest oder auf die Nummer Deiner Version setzen. Wenn Du compat nicht angibst, wird Kompatibiliät zu pre1.3 hergestellt!