
Seguindoesta resposta, ao definir ytick=\empty
a segunda e a terceira subfiguras, as subfiguras não são distribuídas uniformemente, então como posso corrigir essa saída deixando todas as subfiguras terem a mesma largura e distribuídas uniformemente textwidth
?
\RequirePackage{luatex85}
\documentclass{article}
\usepackage{pgfplots,caption,subcaption,mwe,showframe}
\pgfplotsset{compat=newest}
\begin{document}
\begin{figure}
\centering
\pgfmathsetlengthmacro{\myaxiswidth}{0.33\textwidth-width(" 300 ")}% 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, height=0.3\textheight, 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, height=0.3\textheight, scale only axis, ytick=\empty]
\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, height=0.3\textheight, scale only axis, ytick=\empty]
\addplot graphics [xmin=0, xmax=50, ymin=0, ymax=150] {example-image-c};
\end{axis}
\end{tikzpicture}
\end{subfigure}
\end{figure}
\end{document}
Responder1
A razão para o espaço diferente aqui é uma combinação de fatores. Primeiro, como o primeiro gráfico é mais largo que os dois últimos, a distância do lado direito do eixo até a borda do subfigure
é menor para o primeiro do que para os dois últimos.
Além disso, os dois últimos gráficos são mais estreitos que os subfigure
ambientes e, por padrão, o texto dentro deles é alinhado à esquerda. Para consertar essa parte, adicione \centering
no início de cada subfigure
ambiente, mas isso não é suficiente para obter distâncias iguais entre os eixos 1&2 e 2&3, devido ao que está descrito no primeiro parágrafo acima.
Agora, pode muito bem haver outras maneiras, definitivamente não sou bom em encontrar soluções elegantes, mas a solução alternativa que pensei é usar \begin{tikzpicture}[trim axis left]
para todos os três gráficos. trim axis left
é um estilo que altera a caixa delimitadora do tikzpicture
para que qualquer coisa à esquerda do axis
(ticklabels, ylabel) não seja considerada ao determinar a caixa delimitadora. Isso tem o efeito colateral indesejado de que os rótulos do primeiro eixo podem ir para a margem esquerda, mas você pode contrariar isso adicionando algum espaço horizontal antes da primeira subfigura. (Veja o exemplo de código abaixo.)
Também deixei o subfigure
sa um pouco mais estreito e usei \hfill
entre eles para adicionar espaço que preenche a linha.
Dito isso, se você não for adicionar legendas individuais, eu diria que você está usando a ferramenta errada para o trabalho e tornando o código mais longo do que o necessário. Eu sugeriria adicionar a groupplots
biblioteca pgfplots
e adicionar todas as três imagens no mesmo groupplot
ambiente. (Não pensei nisso na sua pergunta anterior.) groupplots
torna esse tipo de coisa muito fácil de fazer.
Com a ajuda \captionof
do caption
pacote você também pode adicionar sublegendas, colocando \node
s com um determinado text width
relativo aos eixos, exemplo abaixo. figure
No entanto, parece ser necessário algum malabarismo com o contador para obter referências cruzadas corretas.
\RequirePackage{luatex85}
\documentclass{article}
\usepackage{pgfplots,caption,subcaption,showframe}
\captionsetup[subfigure]{labelformat=parens}
\usepgfplotslibrary{groupplots}
\pgfplotsset{compat=newest}
\usepackage{cleveref}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}
\begin{groupplot}[
group style={
group name=G,
group size=3 by 1,
y descriptions at=edge left,
horizontal sep=10pt % adjust as needed
},
enlargelimits=false,
width=0.33\textwidth-width("300"),
height=0.3\textheight,
scale only axis]
\nextgroupplot
\addplot graphics [xmin=0, xmax=50, ymin=0, ymax=150] {example-image-a};
\nextgroupplot
\addplot graphics [xmin=0, xmax=50, ymin=0, ymax=150] {example-image-b};
\nextgroupplot
\addplot graphics [xmin=0, xmax=50, ymin=0, ymax=150] {example-image-c};
\end{groupplot}
\refstepcounter{figure} % to get correct
\node [text width=0.33\textwidth-width("300"),below right,align=center] at (G c1r1.south west) {\captionof{subfigure}{Subcaption for the first plot\label{a}}};
\node [text width=0.33\textwidth-width("300"),below right,align=center] at (G c2r1.south west) {\captionof{subfigure}{Subcaption for the second plot}};
\node [text width=0.33\textwidth-width("300"),below right,align=center] at (G c3r1.south west) {\captionof{subfigure}{Subcaption for the third plot}};
\addtocounter{figure}{-1}
\end{tikzpicture}
\caption{..}
\end{figure}
\begin{figure}
\centering
\pgfmathsetlengthmacro{\myaxiswidth}{0.33\textwidth-width("300 ")}
\hspace*{\dimexpr0.33\textwidth-\myaxiswidth}%
\begin{subfigure}[t]{0.3\textwidth}
\centering % added
\begin{tikzpicture}[trim axis left]
\begin{axis}[enlargelimits=false,width=\myaxiswidth, height=0.3\textheight, scale only axis]
\addplot graphics [xmin=0, xmax=50, ymin=0, ymax=150] {example-image-a};
\end{axis}
\end{tikzpicture}
\caption{Subcaption for the first plot}
\label{b}
\end{subfigure}%
\hfill
\begin{subfigure}[t]{0.3\textwidth}
\centering % added
\begin{tikzpicture}[trim axis left]
\begin{axis}[enlargelimits=false,width=\myaxiswidth, height=0.3\textheight, scale only axis, ytick=\empty]
\addplot graphics [xmin=0, xmax=50, ymin=0, ymax=150] {example-image-b};
\end{axis}
\end{tikzpicture}
\caption{Subcaption for the second plot}
\end{subfigure}%
\hfill
\begin{subfigure}[t]{0.3\textwidth}
\centering % added
\begin{tikzpicture}[trim axis left]
\begin{axis}[enlargelimits=false,width=\myaxiswidth, height=0.3\textheight, scale only axis, ytick=\empty]
\addplot graphics [xmin=0, xmax=50, ymin=0, ymax=150] {example-image-c};
\end{axis}
\end{tikzpicture}
\caption{Subcaption for the third plot}
\end{subfigure}
\caption{...}
\end{figure}
\end{document}
A parte superior é para groupplots
código, a parte inferior é para subfigure
código.