0

I have these four tikspicture plots as subfigures. I want to have the axes aligned as well as the subcaptions (a,b,c,d). Also, I want the plots to have the same size and the subcaption letters to be centered underneath each plot. Another problem seems to be that the plots are to close to the margin on the right-hand side.

Thank you very much for any help!

enter image description here

\documentclass[
    12pt,
    a4paper,
    parskip=half,
    toc=bibliography,
    numbers=noendperiod
    ]{scrbook}
\usepackage[
left=3cm,
right=2.5cm,
top=2.5cm,
bottom=2.0cm,
includehead,
includefoot
]{geometry}

\usepackage[UKenglish]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage{scrlayer-scrpage}
\usepackage{lmodern}
\usepackage{textcomp}
\usepackage{amsmath,amssymb}
\usepackage{mwe}
\usepackage{esvect}
\usepackage{mathfixs}
\usepackage[right]{eurosym}
\usepackage{gensymb}
\usepackage[dvipsnames,table,xcdraw]{xcolor}
\usepackage{graphicx}
\usepackage{subcaption}
\usepackage{float}
\usepackage{caption}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\addtokomafont{caption}{\scriptsize}
\usepackage[font={normal}]{caption}
\setkomafont{captionlabel}{\bfseries\rmfamily}


\begin{document}

\begin{figure}[H]
    \begin{subfigure}{0.4\linewidth}
        \begin{tikzpicture}[baseline]
            \begin{axis}[       
                xticklabels={one, two, three, four, five},
                tick label style={font=\scriptsize},
                x tick label style = {rotate=45, anchor=east},
                ylabel={Flux},
                ymin=-0.05,
                ymax=20,
                xtick={1,2,3,4,5},
                ]
                \addplot[color=Blue, mark=*, dashed]
                coordinates {(1,-0.03)(2,4.55)(3,2.55)(4,1.06)(5,16.91)};
            \end{axis}
        \end{tikzpicture}
        \caption{ }
    \end{subfigure}
\hfill
    \begin{subfigure}{0.4\linewidth}
        \begin{tikzpicture}
            \begin{axis}[
                xticklabels={one, four, five, twenty, thirty},
                tick label style={font=\scriptsize},
                x tick label style = {rotate=45, anchor=east},
                ylabel={Flux},
                ymin=0,
                xtick={1,2,3,4,5},
                legend pos=outer north east,
                legend cell align={left}
                ]
                \addplot[color=Blue, mark=*, dashed]
                coordinates {(1,0.00)(2,47.77)(3,1.10)(4,14.68)(5,5.53)};
            \end{axis}
        \end{tikzpicture}
        \caption{ }
    \end{subfigure}
\vfill
    \begin{subfigure}{0.4\linewidth}
        \begin{tikzpicture}
            \begin{axis}[       
                xticklabels={one, nine, seven, thirteen},
                tick label style={font=\scriptsize},
                x tick label style = {rotate=45, anchor=east},
                ylabel={Flux},
                ymin=0,
                xtick={1,2,3,4},
                legend pos=outer north east,
                legend cell align={left}
                ]
                \addplot[color=Blue, mark=*, dashed]
                coordinates {(1,0.78)(2,6.72)(3,4.25)(4,7.97)};
            \end{axis}
        \end{tikzpicture}
        \caption{ }
    \end{subfigure}
\hfill
    \begin{subfigure}{0.4\linewidth}
        \begin{tikzpicture}
            \begin{axis}[       
                xticklabels={one, two},
                tick label style={font=\scriptsize},
                x tick label style = {rotate=45, anchor=east},
                ylabel={Flux},
                ymin=-1,
                ymax=1,
                xtick={1,2},
                legend pos=outer north east,
                legend cell align={left}
                ]
                \addplot[color=Blue, mark=*, dashed]
                coordinates {(1,0.00)(2,-0.02)};
            \end{axis}
        \end{tikzpicture}
        \caption{ }
    \end{subfigure}
    \caption{caption for all plots}
    \label{all_plots}
\end{figure}


\end{document}

Zarko
  • 296,517
  • 1
    When you ask a question here, you can find on the right side a Related section where sometimes you could find answers or at least leads to an answer. For example, in this case, you have (https://tex.stackexchange.com/questions/191160/how-can-i-align-2-plots-vertically?rq=1) and (https://tex.stackexchange.com/questions/191865/aligning-multiple-figures-tikzpicture-vertically-and-horizontally?rq=1). – SebGlav Jul 25 '23 at 17:11
  • 1
    Welcome. // One part of your problem is that a) size of outer bounds vary (must be the same), b) plotsize varies (must be the same), c) space/rectangle needed left and below to put all labels varies (must be the same). // To reduce distration, and sometimes side effects, I highly recommend to delete packages etc., which are not needed for this question. // Once you solved the layout issue to obtain 4 identical plot layouts, which aren't right now, turn to the problem to position images with subcaptions (or treat that one separately and join both approaches later). – MS-SPO Jul 25 '23 at 19:59
  • 1
  • 1
    Wrt. closing this question, the duplicates on alignment address a point of minor importance. I.e. adopting these won't make the diagrams look right. See my previous comment and Zarko's solution. // Relevant is the layout of the pgfplots themselves. – MS-SPO Jul 26 '23 at 08:31

1 Answers1

3

Something like this:

enter image description here

In design of the MWE is considered @MS-SPO comment:

  • prescribed are diagrams widths and heights, in all diagrams are the same
  • prescribed are widths tick labels, in each figure row are the same
  • prescribed diagrams options are merged in the \pgfplotsset in figure (by this MWE code is shoter, but more important the same in all diagrams)
\documentclass[12pt, a4paper,
                parskip=half,
                toc=bibliography,
                numbers=noendperiod
               ]{scrbook}

\usepackage[hmargin={3.0cm, 2.5cm}, vmargin={2.5cm, 2.0cm}, includehead, includefoot ]{geometry}

\usepackage[UKenglish]{babel} \usepackage[T1]{fontenc}

\usepackage{scrlayer-scrpage} \usepackage{subcaption} \usepackage{caption} \addtokomafont{caption}{\scriptsize} \setkomafont{captionlabel}{\bfseries\rmfamily}

\usepackage[dvipsnames,table,xcdraw]{xcolor} \usepackage{pgfplots} \pgfplotsset{compat=1.18}

\begin{document} \begin{figure}[ht] \pgfplotsset{width=\linewidth, height=0.75\linewidth, enlarge y limits=0.1, tick label style={font=\scriptsize}, xticklabel style = {text width=1.4em, align=right, inner sep=2pt, rotate=45, anchor=north east}, ylabel={Flux}, ylabel style = {text width=1em, inner sep=2pt}, yticklabel style = {text width=1.2em, align=right}, % every axis plot post/.append style={color=Blue, dashed, mark=*}, } \begin{subfigure}[t]{0.48\linewidth} \begin{tikzpicture} \begin{axis}[ xtick={1,...,5}, xticklabels={one, two, three, four, five}, ymax=20, ] \addplot coordinates {(1,-0.03)(2,4.55)(3,2.55)(4,1.06)(5,5.93)}; \end{axis} \end{tikzpicture} \caption{} \end{subfigure} \hfill \begin{subfigure}[t]{0.48\linewidth} \begin{tikzpicture} \begin{axis}[ xtick={1,...,5}, xticklabels={one, two, three, four, five}, ymax=50, ] \addplot coordinates {(1,-0.03)(2,47.77)(3,1.10)(4,14.68)(5,16.91)}; \end{axis} \end{tikzpicture} \caption{} \end{subfigure}

\medskip \begin{subfigure}[t]{0.48\linewidth} \begin{tikzpicture} \begin{axis}[ xtick={1,...,4}, xticklabels={one, nine, seven, thirteen}, xticklabel style = {text width=2.4em}, ] \addplot coordinates {(1,0.78)(2,6.72)(3,4.25)(4,7.97)}; \end{axis} \end{tikzpicture} \caption{ } \end{subfigure} \hfill \begin{subfigure}[t]{0.48\linewidth} \begin{tikzpicture} \begin{axis}[ ymin=-1, ymax=1, xtick={1,2}, xticklabels={one, two}, xticklabel style = {text width=2.4em}, ] \addplot coordinates {(1,0.00)(2,-0.02)}; \end{axis} \end{tikzpicture} \caption{ } \end{subfigure} \caption{caption for all plots} \label{all_plots} \end{figure} \end{document}

Zarko
  • 296,517