
この MWE では、親 float 環境 (または)tikzpicture
の割り当てられたスペースをどのように適合させることができますか?figure
subfigure
\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}
編集
以下のコードの出力では、\textwidth
各サブ図の幅を に等しくしているにもかかわらず、サブ図が全体に広がることはありません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]
答え1
3番目のサブ図が別の行に表示される理由は、サブ図の間にスペースがあるためです。コード内の改行はスペースと同じなので、%
後に が必要です\end{subfigure}
。つまり、
\end{subfigure}
%
\begin..
必要なのは
\end{subfigure}%
%
\begin..
または
\end{subfigure}%
\begin..
例えば%
行末のパーセント記号 ( ) は何の目的で使用されますか?
2 番目の問題は、width
a のキーが pgfplots
axis
実際には正確ではないことです。 正確でpgfplots
はないのは、目盛りラベルと軸ラベルが軸自体の外側に 45 ポイントのスペースを占めると想定していることです。 したがって、指定された幅から 45 ポイントを減算し、この幅を軸に使用します。
45pt を他の値に変更することはできませんが、独自の軸幅を計算し、キーを使用して、目盛りラベル/軸ラベルを無視してパラメータが軸に適用されるscale only axis
ように指定できますwidth
。
もっと大雑把な方法は、全体tikzpicture
を に入れて\resizebox
、それをサブ図の幅に合わせて単純に拡大することです。この場合の問題は、フォントのサイズも変更されることです。
最後に、これらにキャプションがない場合、subfigure
環境は無意味であるため、破棄できることに注意してください。
最初の行は の効果を示し\resizebox
、2 行目では軸に計算された幅を使用し、3 行目ではsubfigure
環境なしで同じものを使用しています。showframe
パッケージはテキスト領域の周囲にフレームを出力します。スクリーンショットに表示されている行は次のとおりです。
\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}