1

How can I go about creating a compact two column figure with 3 figures for each column? This is the mess the mess I've created trying to do so.

 \documentclass[a4paper,man,12pt]{scrartcl}
    \setkomafont{disposition}{\normalfont\bfseries}
    \usepackage{geometry}
    \usepackage{siunitx}
    \usepackage[numbers,super]{natbib}
    \usepackage[english]{babel}
    \usepackage{gensymb}
    \usepackage{titling}
    \usepackage{graphicx}
    \graphicspath{ {images/} }
    \usepackage{caption}
    \usepackage{float} 
    \usepackage{xcolor} 
    \usepackage{pgfplots} 
    \usepackage{subcaption}
    \usepackage{amsmath}
    \usepackage{mathptmx}
   \captionsetup{justification =   raggedright,
              singlelinecheck=  false}
\pgfplotsset{compat=1.8}
\usepgfplotslibrary{statistics} 
\usepackage[font=small,labelfont=bf,
   justification=justified,
   format=plain]{caption} % 'format=plain' avoids hanging indentation

\geometry{hmargin={1in,1in},height=9in} %adjusts margins

    \begin{document}

    \begin{figure}[H]

    \begin{subfigure}{0.35\textwidth}
    \centering
    \begin{tikzpicture}
    \begin{axis}
        [ylabel =
                {Y-label},
            yticklabels= {1,2,3,4,5,6},
            xlabel={X label},
            ytick={1,2,3,4,5,6},
            x post scale=1.1, enlarge x limits=0.01, width=1.25\textwidth,
            xmin=0,
            xmax=6000000,
            title=title,
            every x tick scale label/.style={at={(xticklabel cs:1)},anchor=south west}
            ]
        \addplot[
        boxplot prepared={
        median=2.5,
        upper quartile=3,
        lower quartile=2,
            upper whisker=5,
            lower whisker=1,
                every box/.style={very thick},
        every whisker/.style={ultra thick},
        every median/.style={ultra thick},
        },
         x post scale=2.0
        ] coordinates {};
    \end{axis}
    \label{Fig:fig1A}
    \end{tikzpicture}

    \end{subfigure}%
    \hbox{\hspace{3.0cm}\begin{subfigure}{0.35\textwidth}
    \begin{tikzpicture}
    \begin{axis}
         [ylabel =
                {Y-label},
            yticklabels= {1,2,3,4,5,6},
            xlabel={X label},
            ytick={1,2,3,4,5,6},
            x post scale=1.1, enlarge x limits=0.01, width=1.25\textwidth,
            xmin=0,
            xmax=6000000,
            title=title,
            every x tick scale label/.style={at={(xticklabel cs:1)},anchor=south west}
            ]
        \addplot[
        boxplot prepared={
        median=2.5,
        upper quartile=3,
        lower quartile=2,
            upper whisker=5,
            lower whisker=1,
                every box/.style={very thick},
        every whisker/.style={ultra thick},
        every median/.style={ultra thick},
        },
         x post scale=2.0
        ] coordinates {};
    \end{axis}
    \label{1C}
    \end{tikzpicture}
    \end{subfigure}}%
    \begin{subfigure}{.5\textwidth}
      \centering
      \hbox{\hspace{-13.25cm}\textbf{2C}}
      \hbox{\hspace{-14.0cm}\vspace{-11.5cm}\includegraphics[width=0.95\linewidth]{Images/Figure2e.png}}

      \label{fig:sub2}
    \end{subfigure}


    \begin{subfigure}{.5\textwidth}
      \centering
      \hbox{\hspace{0.85cm}\textbf{2E}}
      \hbox{\hspace{0.75cm}\vspace{-8.5cm}\includegraphics[width=0.85\linewidth]{Images/Figure2c.png}}
      \label{fig:sub2}
    \end{subfigure}
    \begin{subfigure}{.5\textwidth}
      \centering
      \hbox{\hspace{1.75cm}\textbf{2D}}
      \hbox{\hspace{3.0cm}\vspace{2.5cm}\includegraphics[width=0.75\linewidth]{Images/Figure2b.png}}
      \label{fig:sub2}
    \end{subfigure}
    \begin{subfigure}{0.5\textwidth}
      \centering
      \hbox{\hspace{9.90cm}\textbf{2F}}
      \hbox{\hspace{10.0cm}\vspace{0.0cm}\includegraphics[width=0.75\linewidth]{Images/Figure2f.png}}
      \label{fig:sub2}
    \end{subfigure}

    \caption{Caption}
    \end{figure}
    \end{document}

Sorry its so messy, wanted to almost exactly replicate the hole I've dug my self into. My issue is that if I try to move the float of some of the figures, they'll just move around the text below it rather than the figure itself. Also, there's so much white space between the figures. enter image description here

3
  • 2
    Welcome to TeX.SE. Even if I insert the instruction \begin{document} between the \usepackage{amsmath} and \begin{figure}[H] directives, I cannot compile your code at present. Some of the TikZ code appears to be off. Please make the code compilable, so that readers can focus on the main issue of your query.
    – Mico
    Feb 2, 2019 at 17:11
  • What does 2F,... stand for? If these are subfigure numbers, why not use the caption command for automated numbering?
    – leandriis
    Feb 2, 2019 at 17:22
  • 2F because I wanted to have the title of the image above it.
    – S.Thomas
    Feb 2, 2019 at 18:45

1 Answer 1

1

to long that can be fit in comment ...

  • from your question is not clear what is your problem:
    • positioning figures
    • positioning sub captions
    • drawing diagrams with \pgfplots ...
  • so far i was i was able to reduce your code (mess as you said) to the following mwe (minimal working example):

    \documentclass[a4paper,man,12pt]{scrartcl}
    \usepackage[hmargin=1in,height=9in]{geometry}
    \usepackage[demo]{graphicx}
    \usepackage{pgfplots}
    \usepackage{subcaption}
    \pgfplotsset{compat=1.16}
    \usepgfplotslibrary{statistics}
    \usepackage[font=small,
                labelfont=bf,
                justification=justified,
                format=plain]{caption} % 'format=plain' avoids hanging indentation
    
    \usepackage{lipsum}
    \begin{document}
    \lipsum[1]
    
    \begin{figure}[htb]
        \centering
    \begin{subfigure}{.45\textwidth}
        \caption{first \texttt{pgfplot} diagram}
        \label{fig:sub1}
    \begin{tikzpicture}
    \begin{axis}[
    width=\textwidth,       % don't prescibe digram width larger as available space!
    ylabel = {Y-label},
    xlabel={X label},
    enlarge x limits=0.01,
    xmin=0, xmax=6000000,
    grid
                ]
        \addplot coordinates {(0,0) (6000000,6)};
    \end{axis}
    \end{tikzpicture}
    \end{subfigure}
    \hfil
    \begin{subfigure}{.45\textwidth}
        \caption{second \texttt{pgfplot} diagram}
        \label{fig:sub2}
    \begin{tikzpicture}
    \begin{axis}[
    width=\textwidth,       % don't prescibe digram width larger as available space!
    ylabel = {Y-label},
    xlabel={X label},
    enlarge x limits=0.01,
    xmin=0, xmax=6000000,
    grid
                ]
        \addplot coordinates {(0,6) (6000000,0)};
    \end{axis}
    \end{tikzpicture}
    \end{subfigure}
    
    \begin{subfigure}{.45\textwidth}
    \includegraphics[width=\linewidth]{Images/Figure2e.png}
        \caption{first}
        \label{fig:sub1}
    \end{subfigure}
    \hfil
    \begin{subfigure}{.45\textwidth}
    \includegraphics[width=\linewidth]{Images/Figure2c.png}
        \caption{second}
        \label{fig:sub2}
    \end{subfigure}
    
    \begin{subfigure}{.45\textwidth}
    \includegraphics[width=\linewidth]{Images/Figure2b.png}
        \caption{third}
        \label{fig:sub3}
    \end{subfigure}
    \hfil
    \begin{subfigure}{0.45\textwidth}
        \centering
    \includegraphics[width=\linewidth]{Images/Figure2f.png}
        \caption{fourth}
        \label{fig:sub2}
    \end{subfigure}
        \caption{Caption}
    \end{figure}
    \end{document}
    

    which generate the following result:

enter image description here

please. clarify, what you expect. the best with some sketch or with help of above mwe.

edit: added are (dummy) examples of diagrams drawn with the pgfplotspackage. observe, how is defined width of diagrams. it should not be greater than width of reserved space with subfigure.

3
  • Overall it is a mix of all figure positioning and sub caption alignment. I've added a picture, hopefully that makes it a but clearer on what I am trying to attempt. Interesting when I attempted to recreate the code you created with my specific problem, it was able to format the images correctly, but it looks like the graphs were misaligned.
    – S.Thomas
    Feb 2, 2019 at 20:01
  • @S.Thomas, (i) please one problem per question, (ii) i edit answer and add examples of sub figures with diagrams drawn with pgfplots (iii) if you have further problems, please ask new question (and use above answer as starting point)
    – Zarko
    Feb 2, 2019 at 20:53
  • My apologies! I think that might be. It thought I was making it simpler by reducing the textwidth so everything would fit on the page. Thank you!
    – S.Thomas
    Feb 2, 2019 at 22:12

You must log in to answer this question.

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