0

I have problems placing subcaptions and captions for minipages. A picture depicts what I want, but a figure included in one graph. Maybe, the right solution wasn't \picture in a previous post. I hope you can help me.

im

\documentclass[11pt]{report}
\usepackage[T1]{fontenc}
\usepackage{titlesec}
\usepackage{calc}
\usepackage{lmodern}
\usepackage{lipsum}
\usepackage{graphicx,picture,calc}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\usetikzlibrary{patterns}
\usepackage{caption}
\usepackage{subcaption}

\begin{document}

\begin{figure}
\centering
\begin{minipage}{0.4\linewidth}
\centering
\begin{tikzpicture}
\begin{axis}[ymin=0,xmin=-20000,x=.001mm,y=1cm, axis x line=bottom,axis y line=left,ylabel={\scriptsize TEXT},clip=false]
    \addplot[mark=none,very thick,red] coordinates{(0,8)(1873,8)(845,7)(3504,7)(1358,6)(4127,6)(1384,5)(4057,5)(1458,4)(3366,4)(2243,3)(1828.5,3)(4189,2)(1710,2)(7393,1)(5661,1)(11723,0)};
    \addplot+[mark=none,fill,pattern=north east lines] coordinates{(0,8)(1873,8)(845,7)(3504,7)(1358,6)(4127,6)(1384,5)(4057,5)(1458,4)(3366,4)(2243,3)(1828.5,3)(4189,2)(1710,2)(7393,1)(5661,1)(11723,0)}\closedcycle;
    \addplot[mark=none]coordinates{(0,0)(0,8)};
\node at (axis cs:1873,8.15) [font=\scriptsize, right] {1873};
\node at (axis cs:3504,7.15) [font=\scriptsize, right] {3504};
\node at (axis cs:4127,6.15) [font=\scriptsize, right] {4127};
\node at (axis cs:4057,5.15) [font=\scriptsize, right] {4057};
\node at (axis cs:3366,4.15) [font=\scriptsize, right] {3366};
\node at (axis cs:2243,3.15) [font=\scriptsize, right] {2243};
\node at (axis cs:4189,2.15) [font=\scriptsize, right] {4189};
\node at (axis cs:7393,1.15) [font=\scriptsize, right] {7393};
\node at (axis cs:11723,0.15) [font=\scriptsize, right] {11723};
    \end{axis}
    \end{tikzpicture}
    \subcaption{Subcaption}
\end{minipage}%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{minipage}{0.4\linewidth}
\centering
\sbox0{
\begin{tikzpicture}[scale=.3]
\draw (0,0)--(0,.4)--(1.575,.4)--(1.575,7.8)--(0,7.8)--(0,8.2)--(3.4,8.2)--(3.4,7.8)--(1.825,7.8)--(1.825,.4)--(3.4,.4)--(3.4,0)--cycle;
\end{tikzpicture}
}
\sbox2{
\begin{tikzpicture}
\begin{axis}[ymin=0,x=.001mm,y=1cm, axis x line=bottom,axis y line=left,hide y axis,clip=false]
    \addplot[mark=none,red,very thick] coordinates{(0,8)(287,8)(2363,7)(2013,7)(6596,6)(6236,6)(12237,5)(11880,5)(19002,4)(18658,4)(26639,3)(26350,3)(34817,2)(34625,2)(43433,1)(43332,1)(51380,0)};
    \addplot+[mark=none,fill,pattern=north east lines] coordinates{(0,8)(287,8)(2363,7)(2013,7)(6596,6)(6236,6)(12237,5)(11880,5)(19002,4)(18658,4)(26639,3)(26350,3)(34817,2)(34625,2)(43433,1)(43332,1)(51380,0)}\closedcycle;
    \addplot [mark=none]coordinates{(0,0)(0,8)};
\node at (axis cs:287,8.15) [font=\scriptsize, right] {287};
\node at (axis cs:2363,7.15) [font=\scriptsize, right] {2363};
\node at (axis cs:6596,6.15) [font=\scriptsize, right] {6596};
\node at (axis cs:12237,5.15) [font=\scriptsize, right] {12237};
\node at (axis cs:19002,4.15) [font=\scriptsize, right] {19002};
\node at (axis cs:26639,3.15) [font=\scriptsize, right] {26639};
\node at (axis cs:34817,2.15) [font=\scriptsize, right] {34817};
\node at (axis cs:43433,1.15) [font=\scriptsize, right] {43433};
\node at (axis cs:51380,0.15) [font=\scriptsize, right] {51380};
    \end{axis}
    \end{tikzpicture}
    }
\begin{picture}(\wd0, \ht0 )
\put(0,0){\usebox0}
%% Adjust the -0.7cm and -0.5cm shifts
\put(\wd0 - \wd2 - 0.5cm,\ht0 - \ht2 - 0.1cm){\usebox{2}}
\end{picture}
    \subcaption{Subcaption}
\end{minipage}%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\caption{Caption}
\end{figure}

\end{document}
4
  • This does not compile for me. Do you miss the package subcaption? Your example is not minimal.
    – LaRiFaRi
    Commented Sep 1, 2014 at 13:15
  • @LaRiFaRi Yes, you are right.
    – Isai
    Commented Sep 1, 2014 at 14:18
  • @Isai can you be more specific as to where the problem lies? Do you simply want to reproduce what's in the picture you showed?
    – greyshade
    Commented Sep 1, 2014 at 14:32
  • @greyshade I updated the picture.
    – Isai
    Commented Sep 1, 2014 at 14:39

1 Answer 1

1

In your case the smaller \sbox was used as the reference inside the picture, thus your alignment was broken. Further damage was done by the \centering inside the minipage which seems to cause the point (0,0) to be shifted. Finally I gave alignment specifiers for the minipages, i.e. [b].

The following should work:

enter image description here

\documentclass[11pt]{report}
\usepackage[T1]{fontenc}
\usepackage{titlesec}
\usepackage{calc}
\usepackage{lmodern}
\usepackage{lipsum}
\usepackage{graphicx,picture,calc}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\usetikzlibrary{patterns}
\usepackage{caption}
\usepackage{subcaption}

\begin{document}

\begin{figure}
\centering
\begin{minipage}[b]{0.4\linewidth}
\centering
\begin{tikzpicture}
\begin{axis}[ymin=0,xmin=-20000,x=.001mm,y=1cm, axis x line=bottom,axis y line=left,ylabel={\scriptsize TEXT},clip=false]
    \addplot[mark=none,very thick,red] coordinates{(0,8)(1873,8)(845,7)(3504,7)(1358,6)(4127,6)(1384,5)(4057,5)(1458,4)(3366,4)(2243,3)(1828.5,3)(4189,2)(1710,2)(7393,1)(5661,1)(11723,0)};
    \addplot+[mark=none,fill,pattern=north east lines] coordinates{(0,8)(1873,8)(845,7)(3504,7)(1358,6)(4127,6)(1384,5)(4057,5)(1458,4)(3366,4)(2243,3)(1828.5,3)(4189,2)(1710,2)(7393,1)(5661,1)(11723,0)}\closedcycle;
    \addplot[mark=none]coordinates{(0,0)(0,8)};
\node at (axis cs:1873,8.15) [font=\scriptsize, right] {1873};
\node at (axis cs:3504,7.15) [font=\scriptsize, right] {3504};
\node at (axis cs:4127,6.15) [font=\scriptsize, right] {4127};
\node at (axis cs:4057,5.15) [font=\scriptsize, right] {4057};
\node at (axis cs:3366,4.15) [font=\scriptsize, right] {3366};
\node at (axis cs:2243,3.15) [font=\scriptsize, right] {2243};
\node at (axis cs:4189,2.15) [font=\scriptsize, right] {4189};
\node at (axis cs:7393,1.15) [font=\scriptsize, right] {7393};
\node at (axis cs:11723,0.15) [font=\scriptsize, right] {11723};
    \end{axis}
    \end{tikzpicture}
    \subcaption{Subcaption}
\end{minipage}%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{minipage}[b]{0.55\linewidth}
%\centering
\sbox0{
\begin{tikzpicture}[scale=.2]
\draw (0,0)--(0,.4)--(1.575,.4)--(1.575,7.8)--(0,7.8)--(0,8.2)--(3.4,8.2)--(3.4,7.8)--(1.825,7.8)--(1.825,.4)--(3.4,.4)--(3.4,0)--cycle;
\end{tikzpicture}
}
\sbox2{
\begin{tikzpicture}
\begin{axis}[ymin=0,x=.001mm,y=1cm, axis x line=bottom,axis y line=left,hide y axis,clip=false]
    \addplot[mark=none,red,very thick] coordinates{(0,8)(287,8)(2363,7)(2013,7)(6596,6)(6236,6)(12237,5)(11880,5)(19002,4)(18658,4)(26639,3)(26350,3)(34817,2)(34625,2)(43433,1)(43332,1)(51380,0)};
    \addplot+[mark=none,fill,pattern=north east lines] coordinates{(0,8)(287,8)(2363,7)(2013,7)(6596,6)(6236,6)(12237,5)(11880,5)(19002,4)(18658,4)(26639,3)(26350,3)(34817,2)(34625,2)(43433,1)(43332,1)(51380,0)}\closedcycle;
    \addplot [mark=none]coordinates{(0,0)(0,8)};
\node at (axis cs:287,8.15) [font=\scriptsize, right] {287};
\node at (axis cs:2363,7.15) [font=\scriptsize, right] {2363};
\node at (axis cs:6596,6.15) [font=\scriptsize, right] {6596};
\node at (axis cs:12237,5.15) [font=\scriptsize, right] {12237};
\node at (axis cs:19002,4.15) [font=\scriptsize, right] {19002};
\node at (axis cs:26639,3.15) [font=\scriptsize, right] {26639};
\node at (axis cs:34817,2.15) [font=\scriptsize, right] {34817};
\node at (axis cs:43433,1.15) [font=\scriptsize, right] {43433};
\node at (axis cs:51380,0.15) [font=\scriptsize, right] {51380};
    \end{axis}
    \end{tikzpicture}
    }
\begin{picture}(\wd0, \ht0 )
\put(0,0){\usebox2}
%% Adjust the -0.7cm and -0.5cm shifts
\put(\wd2 - \wd0 - 1cm,\ht2 - \ht0 - 1cm){\usebox{0}}
\end{picture}
    \subcaption{Subcaption}
\end{minipage}%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\caption{Caption}
\end{figure}

\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .