
Wie kann ich in diesem MWE tikzpicture
den zugewiesenen Speicherplatz der übergeordneten Float-Umgebung ( figure
oder subfigure
) anpassen?
\RequirePackage{luatex85}
\documentclass{article}
\usepackage{pgfplots,caption,subcaption,mwe}
\pgfplotsset{compat=newest}
\begin{document}
\begin{figure}
\begin{subfigure}[t]{0.3\textwidth}
\begin{tikzpicture}
\begin{axis}[enlargelimits=false]
\addplot graphics [
xmin=0,
xmax=50,
ymin=0,
ymax=150,
] {example-image-a};
\end{axis}
\end{tikzpicture}
\end{subfigure}
%
\begin{subfigure}[t]{0.3\textwidth}
\begin{tikzpicture}
\begin{axis}[enlargelimits=false]
\addplot graphics [
xmin=0,
xmax=50,
ymin=0,
ymax=150,
] {example-image-b};
\end{axis}
\end{tikzpicture}
\end{subfigure}
%
\begin{subfigure}[t]{0.3\textwidth}
\begin{tikzpicture}
\begin{axis}[enlargelimits=false]
\addplot graphics [
xmin=0,
xmax=50,
ymin=0,
ymax=150,
] {example-image-c};
\end{axis}
\end{tikzpicture}
\end{subfigure}
\end{figure}
\end{document}
Bearbeiten
Die Ausgabe des untenstehenden Codes bewirkt nicht, dass sich die Unterabbildungen über alles erstrecken, \textwidth
obwohl die Breite jeder Unterabbildung gleich ist 0.33\textwidth
.
\begin{figure}
\centering
\begin{subfigure}[t]{0.33\textwidth}
\begin{tikzpicture}
\begin{axis}[enlargelimits=false,width=\textwidth]
\addplot graphics [
xmin=0,
xmax=50,
ymin=0,
ymax=150,
] {example-image-a};
\end{axis}
\end{tikzpicture}
\end{subfigure}
%
\begin{subfigure}[t]{0.33\textwidth}
\begin{tikzpicture}
\begin{axis}[enlargelimits=false,width=\textwidth]
\addplot graphics [
xmin=0,
xmax=50,
ymin=0,
ymax=150,
] {example-image-b};
\end{axis}
\end{tikzpicture}
\end{subfigure}
%
\begin{subfigure}[t]{0.33\textwidth}
\begin{tikzpicture}
\begin{axis}[enlargelimits=false,width=\textwidth]
\addplot graphics [
xmin=0,
xmax=50,
ymin=0,
ymax=150,
] {example-image-c};
\end{axis}
\end{tikzpicture}
\end{subfigure}
\end{figure}
\lipsum[1]
Antwort1
Der Grund, warum Sie die dritte Unterabbildung in einer separaten Zeile erhalten, ist, dass Sie ein Leerzeichen zwischen den Unterabbildungen haben. Ein Zeilenumbruch im Code ist dasselbe wie ein Leerzeichen, daher benötigen Sie ein %
after \end{subfigure}
. D. h. statt
\end{subfigure}
%
\begin..
du brauchst
\end{subfigure}%
%
\begin..
oder
\end{subfigure}%
\begin..
Siehe zBWozu dienen die Prozentzeichen ( %
) am Zeilenende?
Das zweite Problem ist, dass der width
Schlüssel für a pgfplots
axis
nicht wirklich genau ist. Es pgfplots
wird angenommen, dass die Ticklabels und Achsenbeschriftungen 45pt Platz außerhalb der Achse selbst einnehmen. Daher wird die angegebene Breite genommen, 45pt abgezogen und diese Breite für die Achse verwendet.
Sie können die 45pt nicht in einen anderen Wert ändern, aber Sie können Ihre eigene Achsenbreite berechnen und mit dem scale only axis
Schlüssel angeben, dass der width
Parameter für die Achse gilt, ohne Berücksichtigung von Ticklabels/Achsenbeschriftungen.
tikzpicture
Eine einfachere Methode besteht darin, das Ganze in ein zu setzen \resizebox
und es einfach auf die Breite der Unterabbildung zu skalieren. Das Problem dabei ist, dass auch die Schriftgröße angepasst wird.
subfigure
Beachten Sie zuletzt, dass die Umgebungen ziemlich sinnlos sind und verworfen werden können , wenn Sie keine Untertitel dafür haben .
Die erste Zeile zeigt den Effekt von \resizebox
, in der zweiten habe ich eine berechnete Breite für die Achsen verwendet und in der dritten dasselbe, aber ohne subfigure
Umgebungen. Das showframe
Paket druckt einen Rahmen um den Textbereich, das sind die Zeilen, die im Screenshot zu sehen sind:
\RequirePackage{luatex85}
\documentclass{article}
\usepackage{pgfplots,subcaption,showframe}
\pgfplotsset{compat=newest}
\begin{document}
\begin{figure}
\centering
\begin{subfigure}[t]{0.33\textwidth}
\resizebox{\textwidth}{!}{\begin{tikzpicture}
\begin{axis}[enlargelimits=false,width=\textwidth]
\addplot graphics [
xmin=0,
xmax=50,
ymin=0,
ymax=150,
] {example-image-a};
\end{axis}
\end{tikzpicture}}
\end{subfigure}%
%
\begin{subfigure}[t]{0.33\textwidth}
\resizebox{\textwidth}{!}{\begin{tikzpicture}
\begin{axis}[enlargelimits=false,width=\textwidth]
\addplot graphics [
xmin=0,
xmax=50,
ymin=0,
ymax=150,
] {example-image-b};
\end{axis}
\end{tikzpicture}}
\end{subfigure}%
%
\begin{subfigure}[t]{0.33\textwidth}
\resizebox{\textwidth}{!}{\begin{tikzpicture}
\begin{axis}[enlargelimits=false,width=\textwidth]
\addplot graphics [
xmin=0,
xmax=50,
ymin=0,
ymax=150,
] {example-image-c};
\end{axis}
\end{tikzpicture}}
\end{subfigure}
\pgfmathsetlengthmacro{\myaxiswidth}{0.33\textwidth-width(" 150 ")}% subtract width of widest ticklabel, with a space on each side
\begin{subfigure}[t]{0.33\textwidth}
\begin{tikzpicture}
\begin{axis}[enlargelimits=false,width=\myaxiswidth,scale only axis]
\addplot graphics [
xmin=0,
xmax=50,
ymin=0,
ymax=150,
] {example-image-a};
\end{axis}
\end{tikzpicture}
\end{subfigure}%
%
\begin{subfigure}[t]{0.33\textwidth}
\begin{tikzpicture}
\begin{axis}[enlargelimits=false,width=\myaxiswidth,scale only axis]
\addplot graphics [
xmin=0,
xmax=50,
ymin=0,
ymax=150,
] {example-image-b};
\end{axis}
\end{tikzpicture}
\end{subfigure}%
%
\begin{subfigure}[t]{0.33\textwidth}
\begin{tikzpicture}
\begin{axis}[enlargelimits=false,width=\myaxiswidth,scale only axis]
\addplot graphics [
xmin=0,
xmax=50,
ymin=0,
ymax=150,
] {example-image-c};
\end{axis}
\end{tikzpicture}
\end{subfigure}
\begin{tikzpicture}
\begin{axis}[enlargelimits=false,width=\myaxiswidth,scale only axis]
\addplot graphics [
xmin=0,
xmax=50,
ymin=0,
ymax=150,
] {example-image-a};
\end{axis}
\end{tikzpicture}%
\begin{tikzpicture}
\begin{axis}[enlargelimits=false,width=\myaxiswidth,scale only axis]
\addplot graphics [
xmin=0,
xmax=50,
ymin=0,
ymax=150,
] {example-image-b};
\end{axis}
\end{tikzpicture}%
\begin{tikzpicture}
\begin{axis}[enlargelimits=false,width=\myaxiswidth,scale only axis]
\addplot graphics [
xmin=0,
xmax=50,
ymin=0,
ymax=150,
] {example-image-c};
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}