3

I have the next graphic

enter image description here

As you can see, the subcaption (b) is not centered from the corresponding subfigure like (a). If I increase the value for [.51\linewidth] unwanted things happen. I'm using subcaption package with memoir because the native memoir tools for subfigures show problems with flush right. The code for picture above is:

\documentclass[11pt]{memoir}

\setstocksize{23cm}{15.9cm} 
\settrimmedsize{23cm}{15.9cm}{*} 
\settrims{0pt}{0pt} 
\settypeblocksize{17.8cm}{11.3cm}{*} 
\setlrmargins{2.3cm}{*}{*} 
\setulmargins{6.4\onelineskip}{*}{*} 
\setheadfoot{1.18\onelineskip}{\onelineskip} 
\setheaderspaces{4.1\onelineskip}{*}{*} 
\checkandfixthelayout[lines] 

\usepackage{amsmath,amssymb,amsthm}
\usepackage[english]{babel}
\usepackage{blindtext}
\usepackage{subcaption}
\usepackage{tikz,pgfplots}
\pgfplotsset{compat=1.10}
\usepgfplotslibrary{fillbetween}
\usetikzlibrary{arrows}
\pgfplotsset{
/pgfplots/area style/.style={%
area cycle list,
area legend,
axis on top,
}}

\begin{document}

\blindtext\blindtext

\begin{figure}[b]
%\centering
\subcaptionbox{A cat\label{cat}}{\begin{tikzpicture}[scale=0.71]
 \begin{axis}[axis equal,axis on top,axis lines=center,enlargelimits=false,xlabel=$x(t)$,ylabel=$y(t)$,xmax=2.5,xmin=-2.2,ymax=2.5,ymin=-2.2,area legend,xtick=\empty,ytick= \empty %,legend entries={$\Ran f$}]
\addplot[draw=blue!30!white,fill=blue!30!white,
domain=-2:2,samples=120] {sqrt(4-x^2)};
%\addlegendimage{fill=blue!30!white,area legend}
%\addlegendentry{$\Ran f$}
\addplot[draw=blue!30!white,fill=blue!30!white,
domain=-2:2,samples=120] {-sqrt(4-x^2)};

\addplot[white,fill,
domain=-1:1,samples=120] {sqrt(1-x^2)};
\addplot[white,fill,
domain=-1:1,samples=120] {-sqrt(1-x^2)};
%\node at (380,170) {$x'(t)$};
%\node at (20,170) {$y'(t)$};
\end{axis}
\end{tikzpicture}}
\subcaptionbox{An elephant\label{elephant}}[.51\linewidth]
{\begin{tikzpicture}[scale=0.71,/pgf/declare function={f=1/x;}]
\begin{axis}[axis x line=center,axis y line=center,xtick=\empty,ytick=  \empty,xlabel=$x(t)$,
ylabel=$y(t)$,] 
\addplot [red!30!white,name path=f,domain=-3:3, samples=60] {f};

\path[name path=axis] (axis cs:\pgfkeysvalueof{/pgfplots/xmin},0) --  (axis cs:\pgfkeysvalueof{/pgfplots/xmax},0);

\addplot[red!30!white] fill between[of=f and axis];
\end{axis}
\end{tikzpicture}}
\caption{Two animals}\label{animals}
\end{figure}
\end{document}

How I control that?

  • From what I can see, the second plot has a narrower bounding box than the area it occupies. – egreg Apr 23 '15 at 21:21
  • Is possible, but I can't see that in code ... – juanuni Apr 23 '15 at 22:37
  • I just surrounded the tikzpicture with \fbox{...} and saw what TeX is thinking the bounding box is. Or try switching the pictures, you'll see that the hyperbola overlaps the other one. – egreg Apr 23 '15 at 22:38
  • :o I surround the second tikzpicture with \fbox{...} and the graphic isn't centered ... – juanuni Apr 23 '15 at 22:51
4

Instead of passing scale=0.71 to tikzpicture pass it to the axis options. I have also added ylabel style={anchor=west} to put y label little up.

\documentclass[11pt]{memoir}

\setstocksize{23cm}{15.9cm}
\settrimmedsize{23cm}{15.9cm}{*}
\settrims{0pt}{0pt}
\settypeblocksize{17.8cm}{11.3cm}{*}
\setlrmargins{2.3cm}{*}{*}
\setulmargins{6.4\onelineskip}{*}{*}
\setheadfoot{1.18\onelineskip}{\onelineskip}
\setheaderspaces{4.1\onelineskip}{*}{*}
\checkandfixthelayout[lines]

\usepackage{amsmath,amssymb,amsthm}
\usepackage[english]{babel}
\usepackage{blindtext}
\usepackage{subcaption}
\usepackage{tikz,pgfplots}
\pgfplotsset{compat=1.10}
\usepgfplotslibrary{fillbetween}
\usetikzlibrary{arrows}
\pgfplotsset{
/pgfplots/area style/.style={%
area cycle list,
area legend,
axis on top,
}}

\begin{document}

\blindtext\blindtext

\begin{figure}[b]
%\centering
\subcaptionbox{A cat\label{cat}}{\begin{tikzpicture}
 \begin{axis}[scale=0.71,axis equal,axis on top,axis lines=center,enlargelimits=false,xlabel=$x(t)$,ylabel=$y(t)$,xmax=2.5,xmin=-2.2,ymax=2.5,ymin=-2.2,area legend,xtick=\empty,ytick= \empty,
ylabel style={anchor=west} %,legend entries={$\Ran f$}
]
\addplot[draw=blue!30!white,fill=blue!30!white,
domain=-2:2,samples=120] {sqrt(4-x^2)};
%\addlegendimage{fill=blue!30!white,area legend}
%\addlegendentry{$\Ran f$}
\addplot[draw=blue!30!white,fill=blue!30!white,
domain=-2:2,samples=120] {-sqrt(4-x^2)};

\addplot[white,fill,
domain=-1:1,samples=120] {sqrt(1-x^2)};
\addplot[white,fill,
domain=-1:1,samples=120] {-sqrt(1-x^2)};
%\node at (380,170) {$x'(t)$};
%\node at (20,170) {$y'(t)$};
\end{axis}
\end{tikzpicture}}
\subcaptionbox{An elephant\label{elephant}}[.51\linewidth]
{\begin{tikzpicture}[/pgf/declare function={f=1/x;}]
\begin{axis}[scale=0.71,axis x line=center,axis y line=center,xtick=\empty,ytick=  \empty,xlabel=$x(t)$,
ylabel=$y(t)$,,
ylabel style={anchor=west}]
\addplot [red!30!white,name path=f,domain=-3:3, samples=60] {f};

\path[name path=axis] (axis cs:\pgfkeysvalueof{/pgfplots/xmin},0) --  (axis cs:\pgfkeysvalueof{/pgfplots/xmax},0);

\addplot[red!30!white] fill between[of=f and axis];
\end{axis}
\end{tikzpicture}}
\caption{Two animals}\label{animals}
\end{figure}
\end{document}

enter image description here

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.