Seite 1 von 1

Anordnung von zwei Diagrammen nebeneinander (mit Komma in xaxis)

Verfasst: Mi 17. Aug 2022, 08:51
von Kazter
Hallo zusammen,
leider komme ich nicht weiter.. Habe das Problem, dass die Ausrichtung der Bildunterschrift verrutscht, wenn ein Diagramm in der X-Achse eine Kommadarstellung hat und das andere nicht.

Kann mir jemand helfen. Vielen Dank!!
test.png
\documentclass{article}
\usepackage{caption,subfig}
\usepackage{pgfplots}

\pgfplotsset{
   compat=newest,
   /pgf/number format/use comma,
}

\begin{document}
\begin{figure}[htbp]
\centering
\pgfplotsset{width=0.45\textwidth, height=.25\textheight}
\subfloat[Caption 1 Caption 1 Caption 1 Caption 1 Caption 1]{%
\begin{tikzpicture}[baseline]
\begin{axis}[
    xmin=0,
    xmax=1.80,
    ymin=0,
    ymax=60000,
    xlabel={label x},
    ylabel={label y}
    ]
    \addplot {x^3 + 3*x + 10000};
    \addlegendentry{\(x^3 + 3x + 10000\)}   
\end{axis}
\end{tikzpicture}
}%
\hfil
\subfloat[Caption 2 Caption 2 Caption 2 Caption 2 Caption 2]{%
\begin{tikzpicture}[baseline]
\begin{axis}[
    xmin=-25,
    xmax=25,
    ymin=0,
    ymax=100,
    xlabel={label x},
    ylabel={label y}
    ]
    \addplot {x^3 + 3*x + 1};
    \addlegendentry{\(x^3 + 3x + 1\)}
\end{axis}
\end{tikzpicture}
}%
\caption{Caption 3}
\end{figure}

\end{document}

Re: Anordnung von zwei Diagrammen nebeneinander (mit Komma in xaxis)

Verfasst: Mi 17. Aug 2022, 20:43
von rais
Wenn Du genau hinschaust, siehst Du, daß die beiden `label x' bereits auf unterschiedlicher Höhe landen. Die Kommata besitzen eine Tiefe, die besagte Marke etwas weiter nach unten drängt, als die andere. Versuch es so:
\documentclass{article}
\usepackage{caption,subfig}
\usepackage{pgfplots}

\pgfplotsset{
   compat=newest,
   /pgf/number format/use comma,
   x tick label style={text depth=0.25ex}%<--
}

\begin{document}
\begin{figure}[htbp]
\centering
\pgfplotsset{width=0.45\textwidth, height=.25\textheight}
\subfloat[Caption 1 Caption 1 Caption 1 Caption 1 Caption 1]{%
\begin{tikzpicture}[baseline]
\begin{axis}[
    xmin=0,
    xmax=1.80,
    ymin=0,
    ymax=60000,
    xlabel={label x},
    ylabel={label y}
    ]
    \addplot {x^3 + 3*x + 10000};
    \addlegendentry{\(x^3 + 3x + 10000\)}   
\end{axis}
\end{tikzpicture}
}%
\hfil
\subfloat[Caption 2 Caption 2 Caption 2 Caption 2 Caption 2]{%
\begin{tikzpicture}[baseline]
\begin{axis}[
    xmin=-25,
    xmax=25,
    ymin=0,
    ymax=100,
    xlabel={label x},
    ylabel={label y}
    ]
    \addplot {x^3 + 3*x + 1};
    \addlegendentry{\(x^3 + 3x + 1\)}
\end{axis}
\end{tikzpicture}
}%
\caption{Caption 3}
\end{figure}

\end{document}
BTW: der Wert für `text depth' stammt hier aus der tikz-Doku, schau dort nach `dance around' (derzeit am Ende von Abschnitt 5.1) :wink:

VG
Rainer

Re: Anordnung von zwei Diagrammen nebeneinander (mit Komma in xaxis)

Verfasst: Mo 22. Aug 2022, 01:02
von esdd
Man kann auch typeset ticklabels with strut entweder global in der Präambel
\pgfplotsset{
   compat=newest,
   /pgf/number format/use comma,
   typeset ticklabels with strut
}
oder lokal verwenden:
\documentclass{article}
\usepackage{caption,subfig}
\usepackage{pgfplots}

\pgfplotsset{
   compat=newest,
   /pgf/number format/use comma,
}

\begin{document}
\begin{figure}[htbp]
\centering
\pgfplotsset{
  width=0.45\textwidth, height=.25\textheight,
  typeset ticklabels with strut% <- eingefügt
}
\subfloat[Caption 1 Caption 1 Caption 1 Caption 1 Caption 1]{%
\begin{tikzpicture}[baseline]
\begin{axis}[
    xmin=0,
    xmax=1.80,
    ymin=0,
    ymax=60000,
    xlabel={label x},
    ylabel={label y}
    ]
    \addplot {x^3 + 3*x + 10000};
    \addlegendentry{\(x^3 + 3x + 10000\)}   
\end{axis}
\end{tikzpicture}
}%
\hfil
\subfloat[Caption 2 Caption 2 Caption 2 Caption 2 Caption 2]{%
\begin{tikzpicture}[baseline]
\begin{axis}[
    xmin=-25,
    xmax=25,
    ymin=0,
    ymax=100,
    xlabel={label x},
    ylabel={label y}
    ]
    \addplot {x^3 + 3*x + 1};
    \addlegendentry{\(x^3 + 3x + 1\)}
\end{axis}
\end{tikzpicture}
}%
\caption{Caption 3}
\end{figure}

\end{document}

Re: Anordnung von zwei Diagrammen nebeneinander (mit Komma in xaxis)

Verfasst: Do 25. Aug 2022, 19:59
von Kazter
Erst einmal vielen Dank für Eure Antworten!

Habe jetzt etwas erweitert und bekomme wieder Probleme mit der Ausrichtung, wenn ich das Paket "siunitx" einbinde...

Habe sowohl die Variante mit
typeset ticklabels with strut
als auch mit
x tick label style={text depth=0.25ex}
probiert..
\documentclass{article}
\usepackage{caption,subfig}
\usepackage{pgfplots}

\pgfplotsset{
   compat=newest,
   /pgf/number format/use comma,
}

\usepackage{siunitx}% <- eingefügt
\sisetup{
	locale = DE, 
	group-minimum-digits=4,
	per-mode=symbol-or-fraction,
  }

\begin{document}
\begin{figure}[htbp]
\centering
\pgfplotsset{
  width=0.45\textwidth, height=.25\textheight,
  typeset ticklabels with strut
}
\subfloat[Caption 1 Caption 1 Caption 1 Caption 1 Caption 1]{%
\begin{tikzpicture}[baseline]
\begin{axis}[
    xmin=0,
    xmax=1.80,
    ymin=0,
    ymax=60000,
    xlabel={label x \si{\cubic\metre\per\hour}},% <- eingefügt
    ylabel={label y}
    ]
    \addplot {x^3 + 3*x + 10000};
    \addlegendentry{\(x^3 + 3x + 10000\)}   
\end{axis}
\end{tikzpicture}
}%
\hfil
\subfloat[Caption 2 Caption 2 Caption 2 Caption 2 Caption 2]{%
\begin{tikzpicture}[baseline]
\begin{axis}[
    xmin=-25,
    xmax=25,
    ymin=0,
    ymax=100,
    xlabel={label x \si{\litre\per\hour}},% <- eingefügt
    ylabel={label y}
    ]
    \addplot {x^3 + 3*x + 1};
    \addlegendentry{\(x^3 + 3x + 1\)}
\end{axis}
\end{tikzpicture}
}%
\caption{Caption 3}
\end{figure}

\end{document}

Re: Anordnung von zwei Diagrammen nebeneinander (mit Komma in xaxis)

Verfasst: Fr 26. Aug 2022, 08:54
von Gute*r Gȧst*in
Dieses Mal sind wohl nicht die ticks label, sondern die xlabel das Problem. Die haben (durch den Exponenten) eine unterschiedliche Höhe. Im Beispiel kann das recht einfach über explizite \strut gelöst werden:
\documentclass{article}
\usepackage{caption,subfig}
\usepackage{pgfplots}

\pgfplotsset{
   compat=newest,
   /pgf/number format/use comma,
}

\usepackage{siunitx}
\sisetup{
	locale = DE, 
	group-minimum-digits=4,
	per-mode=symbol-or-fraction,
  }

\begin{document}
\begin{figure}[htbp]
\centering
\pgfplotsset{
  width=0.45\textwidth, height=.25\textheight,
  typeset ticklabels with strut
}
\subfloat[Caption 1 Caption 1 Caption 1 Caption 1 Caption 1]{%
\begin{tikzpicture}[baseline]
\begin{axis}[
    xmin=0,
    xmax=1.80,
    ymin=0,
    ymax=60000,
    xlabel={label x \strut\si{\cubic\metre\per\hour}},% <- \strut eingefügt
    ylabel={label y}
    ]
    \addplot {x^3 + 3*x + 10000};
    \addlegendentry{\(x^3 + 3x + 10000\)}   
\end{axis}
\end{tikzpicture}
}%
\hfil
\subfloat[Caption 2 Caption 2 Caption 2 Caption 2 Caption 2]{%
\begin{tikzpicture}[baseline]
\begin{axis}[
    xmin=-25,
    xmax=25,
    ymin=0,
    ymax=100,
    xlabel={label x \strut\si{\litre\per\hour}},% <- \strut eingefügt
    ylabel={label y}
    ]
    \addplot {x^3 + 3*x + 1};
    \addlegendentry{\(x^3 + 3x + 1\)}
\end{axis}
\end{tikzpicture}
}%
\caption{Caption 3}
\end{figure}

\end{document}
Das geht häufig aber nicht immer so einfach. Sobald die beispielsweise unterschiedliche Zeilenzahl haben, wird es das so nicht mehr funktionieren.

Re: Anordnung von zwei Diagrammen nebeneinander (mit Komma in xaxis)

Verfasst: Fr 26. Aug 2022, 08:56
von Kazter
Mit etwas basteln, habe ich jetzt folgendes gefunden:

x label style={yshift=-3.00ex,anchor=south}

im lokalen \pgfplotsset{...}, siehe MWE.

Bin aber auch gerne für Alternativen offen ;)
\documentclass{article}
\usepackage{caption,subfig}
\usepackage{pgfplots}

\pgfplotsset{
   compat=newest,
   /pgf/number format/use comma,
}

\usepackage{siunitx}
\sisetup{
	locale = DE, 
	group-minimum-digits=4,
	per-mode=symbol-or-fraction,
  }

\begin{document}
\begin{figure}[htbp]
\centering
\pgfplotsset{
  width=0.45\textwidth, height=.25\textheight,
  typeset ticklabels with strut,
  x label style={yshift=-3.00ex,anchor=south}% <- \strut eingefügt
}
\subfloat[Caption 1 Caption 1 Caption 1 Caption 1 Caption 1]{%
\begin{tikzpicture}[baseline]
\begin{axis}[
    xmin=0,
    xmax=1.80,
    ymin=0,
    ymax=60000,
    xlabel={label x \strut\si{\cubic\metre\per\hour}},% <- \strut eingefügt
    ylabel={label y}
    ]
    \addplot {x^3 + 3*x + 10000};
    \addlegendentry{\(x^3 + 3x + 10000\)}   
\end{axis}
\end{tikzpicture}
}%
\hfil
\subfloat[Caption 2 Caption 2 Caption 2 Caption 2 Caption 2]{%
\begin{tikzpicture}[baseline]
\begin{axis}[
    xmin=-25,
    xmax=25,
    ymin=0,
    ymax=100,
    xlabel={label x \strut\si{\litre\per\hour}},% <- \strut eingefügt
    ylabel={label y}
    ]
    \addplot {x^3 + 3*x + 1};
    \addlegendentry{\(x^3 + 3x + 1\)}
\end{axis}
\end{tikzpicture}
}%
\caption{Caption 3}
\end{figure}

\end{document}