1

SOLUTION: By changing the caption setup and including "raggedright" I was able to solve the problem

\captionsetup[figure]{font=small,labelfont=bf, singlelinecheck=false, justification=raggedright, skip=5pt}

I have a bunch of graphs, but I have some problems with the alignment of the captions and all the others post about this doesn't solve the problem. I want a vertical alignment so that the captions starts at the same place (see picture) for all graphs, but how?

Short code:

\documentclass[11pt]{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\usepackage{float}
\usepackage{subcaption}
\captionsetup[figure]{font=small,labelfont=bf, skip=5pt} %default=10pt

\begin{document}
    \begin{figure}[t][H]
    \hspace*{-2cm} 
    \begin{minipage}{8.25cm} 
        \begin{tikzpicture}[scale=1] 
        \caption{Longevity - Minimum Variance}    
        \label{LongGraph5} 
    \end{minipage}
    \begin{minipage}[t]{8.25cm} 
        \begin{tikzpicture}[scale=1] 
        \caption{Longevity - Tangency Portfolio}    
        \label{LongGraph6} 
    \end{minipage}
\end{figure}

\begin{figure}[H]
    \hspace*{-2cm} 
    \begin{minipage}[t]{8.25cm}   
    \begin{tikzpicture}[scale=1]
        \caption{Longevity - Sortino}   
        \label{LongGraph7}  
    \end{minipage}
    \begin{minipage}[t]{8.25cm} 
        \begin{tikzpicture}[scale=1] 
        \caption{Longevity - Risk Longevity}   
        \label{LongGraph8}
    \end{minipage}
\end{figure}
\end{document}

enter image description here

Minimal Working Example:

    \documentclass[11pt]{article}
    \usepackage{pgfplots}
    \pgfplotsset{compat=1.15}
    \usepackage{float}
    \usepackage{subcaption}

    \usepackage{mwe}

    \captionsetup[figure]{font=small,labelfont=bf, skip=5pt} %default=10pt

    \begin{document} 

    \begin{figure}[H]
    \hspace*{-2cm} 
    \begin{minipage}[t]{8.25cm} 
    \includegraphics{example-image-1x1} 
        \caption{Longevity - Minimum Variance}    
        \label{LongGraph5} 
    \end{minipage}
    \begin{minipage}[t]{8.25cm} 
    \includegraphics{example-image-1x1}
        \caption{Longevity - Tangency Portfolio}    
        \label{LongGraph6} 
    \end{minipage}
    \end{figure}

    \begin{figure}[H]
    \hspace*{-2cm} 
    \begin{minipage}[t]{8.25cm}
        \includegraphics{example-image-1x1}
        \caption{Longevity - Sortino}   
        \label{LongGraph7}  
    \end{minipage}
    \begin{minipage}[t]{8.25cm} 
        \includegraphics{example-image-1x1}
        \caption{Longevity - Risk Longevity}   
        \label{LongGraph8} 
    \end{minipage}
    \end{figure}

\end{document}

EDIT: Code including the graphs

\documentclass[11pt]{article}
    \usepackage{pgfplots}
    \pgfplotsset{compat=1.15}
    \usepackage{float}
    \usepackage{subcaption}

    \captionsetup[figure]{font=small,labelfont=bf, skip=5pt} %default=10pt

    %Color definitions
    \definecolor{green}{RGB}{0, 102, 0}
    \definecolor{blue1}{RGB}{0, 125, 255}
    \definecolor{blue2}{RGB}{0, 102, 204}
    \definecolor{blue3}{RGB}{0, 76, 153}
    \definecolor{blue4}{RGB}{0, 51, 102}

    \begin{document}
    \section{Bonus Potential - Side by Side}
    \begin{figure}[H]
    \hspace*{-2cm} 
    \begin{minipage}[t]{8.25cm} 
        \begin{tikzpicture}[scale=1] 
        \begin{axis}[
        xlabel={Bonus Potential (bn)},
        ylabel={Frequency},     
        xmin=0, xmax=600,
        ymin=0, ymax=80,
        xtick={0,100, 200,300,400,500,600},
        ytick={0,10,20,30,40,50,60,70,80},
        xtick pos=bottom,ytick pos=left,      
        legend pos=north west,
        legend style={font=\tiny}]
        \legend{-20\%, -10\%, 0\%*, +10\%, +20\%},
        \addplot[color=blue1, style={line width=0.7pt},smooth]
        coordinates {
        (120,0)
        (180,0)
        (240,39)
        (300,55)
        (360,6)
        (420,0)
        };       
        \addplot[color=blue2,style={line width=0.8pt}, smooth]
        coordinates {
        (120,0)
        (180,1)
        (240,30)
        (300,59)
        (360,9)
        (420,1)
        (480,0)
        };   
        \addplot[color=green,style={line width=0.9pt}, smooth]
        coordinates {
        (120,0)
        (180,5.8)
        (240,59.8)
        (300,34.2)
        (360,0.2)
        (420,0)
        };  
        \addplot[color=blue3,style={line width=0.9pt}, smooth]
        coordinates {
        (120,0)
        (180,1)
        (240,31)
        (300,62)
        (360,6)
        (420,0)
        };   
        \addplot[color=blue4,style={line width=1pt}, smooth]
        coordinates {
        (120,0)
        (180,1)
        (240,34)
        (300,52)
        (360,13)
        (420,0)
        };        
        \end{axis}  
        \end{tikzpicture}   
        \caption{Longevity - Minimum Variance}    
        \label{LongGraph5} 
    \end{minipage}
    \begin{minipage}[t]{8.25cm} 
        \begin{tikzpicture}[scale=1] 
        \begin{axis}[
        xlabel={Bonus Potential (bn)},
        ylabel={Frequency},     
        xmin=0, xmax=600,
        ymin=0, ymax=80,
        xtick={0,100, 200,300,400,500,600},
        ytick={0,10,20,30,40,50,60,70,80},
        xtick pos=bottom,ytick pos=left,      
        legend pos=north west,
        legend style={font=\tiny}]
        \legend{-20\%, -10\%, 0\%*, +10\%, +20\%},
        \addplot[color=blue1, style={line width=0.7pt},smooth]
        coordinates {
        (180,0)
        (240,4)
        (300,35)
        (360,51)
        (420,10)
        (480,0)
        };       
        \addplot[color=blue2,style={line width=0.8pt}, smooth]
        coordinates {
        (180,0)
        (240,1)
        (300,31)
        (360,49)
        (420,18)
        (480,1)
        (540,0)
        };   
        \addplot[color=green,style={line width=1pt}, smooth]
        coordinates {
        (180,0)
        (240,10.5)
        (300,56.4)
        (360,32.5)
        (420,0.6)
        (480,0)
        };  
        \addplot[color=blue3,style={line width=0.9pt}, smooth]
        coordinates {
        (180,0)
        (240,31)
        (300,53)
        (360,16)
        (420,0)
        };   
        \addplot[color=blue4,style={line width=1pt}, smooth]
        coordinates {
        (180,0)
        (240,1)
        (300,33)
        (360,43)
        (420,23)
        (480,0)
        };        
        \end{axis}  
        \end{tikzpicture}   
        \caption{Longevity - Tangency Portfolio}    
        \label{LongGraph6} 
    \end{minipage}
    \end{figure}

    \begin{figure}[H]
    \hspace*{-2cm} 
    \begin{minipage}[t]{8.25cm}  
    \begin{tikzpicture}[scale=1] 
        \begin{axis}[
        xlabel={Bonus Potential (bn)},
        ylabel={Frequency},     
        xmin=0, xmax=600,
        ymin=0, ymax=80,
        xtick={0,100, 200,300,400,500,600},
        ytick={0,10,20,30,40,50,60,70,80},
        xtick pos=bottom,ytick pos=left,      
        legend pos=north west,
        legend style={font=\tiny}]
        \legend{-20\%, -10\%, 0\%*, +10\%, +20\%},
        \addplot[color=blue1, style={line width=0.7pt},smooth]
        coordinates {
        (180,0)
        (240,31)
        (300,53)
        (360,16)
        (420,0)
        };       
        \addplot[color=blue2,style={line width=0.8pt}, smooth]
        coordinates {
        (180,0)
        (240,37)
        (300,45)
        (360,17)
        (420,1)
        (480,0)
        };   
        \addplot[color=green,style={line width=0.9pt}, smooth]
        coordinates {
        (120,0)
        (180,3.3)
        (240,50)
        (300,46.3)
        (360,0.4)
        (420,0)
        };  
        \addplot[color=blue3,style={line width=0.9pt}, smooth]
        coordinates {
        (180,0)
        (240,31)
        (300,53)
        (360,16)
        (420,0)
        };   
        \addplot[color=blue4,style={line width=1pt}, smooth]
        coordinates {
        (180,0)
        (240,29)
        (300,55)
        (360,16)
        (420,0)
        };        
        \end{axis}  
        \end{tikzpicture}  
        \caption{Longevity - Sortino}   
        \label{LongGraph7}  
    \end{minipage}
    \begin{minipage}[t]{8.25cm} 
        \begin{tikzpicture}[scale=1] 
        \begin{axis}[
        xlabel={Bonus Potential (bn)},
        ylabel={Frequency},     
        xmin=0, xmax=600,
        ymin=0, ymax=80,
        xtick={0,100, 200,300,400,500,600},
        ytick={0,10,20,30,40,50,60,70,80},
        xtick pos=bottom,ytick pos=left,      
        legend pos=north west,
        legend style={font=\tiny}]
        \legend{-20\%, -10\%, 0\%*, +10\%, +20\%},
        \addplot[color=blue1, style={line width=0.7pt},smooth]
        coordinates {
        (180,0)
        (240,4)
        (300,29)
        (360,49)
        (420,18)
        (480,0)
        };       
        \addplot[color=blue2,style={line width=0.8pt}, smooth]
        coordinates {
        (180,0)
        (240,1)
        (300,27)
        (360,45)
        (420,26)
        (480,1)
        (540,0)
        };   
        \addplot[color=green,style={line width=0.9pt}, smooth]
        coordinates {
        (180,0)
        (240,9.7)
        (300,47.8)
        (360,41.4)
        (420,1.1)
        (480,0)
        };  
        \addplot[color=blue3,style={line width=0.9pt}, smooth]
        coordinates {
        (180,0)
        (240,1)
        (300,34)
        (360,48)
        (420,17)
        (480,0)
        };   
        \addplot[color=blue4,style={line width=1pt}, smooth]
        coordinates {
        (180,0)
        (240,1)
        (300,33)
        (360,43)
        (420,23)
        (480,0)
        };        
        \end{axis}  
        \end{tikzpicture}   
        \caption{Longevity - Risk Longevity}   
        \label{LongGraph8} 
    \end{minipage}
    \end{figure}


    \end{document}
2
  • Your minimal working example (MWE) doesn't compile. Please complete it with example-images.
    – CarLaTeX
    Apr 28 '18 at 7:42
  • @CarLaTeX I edited the post and added the entire code, I originally left out (collapsed) the graphs do to their length. Apr 28 '18 at 7:55
1

You already found the solution by yourself (please post an answer instead of editing your question with the answer, even if your question probably is a duplicate), but since you loaded subcaption package, why aren't you using it?

I have also scaled your images, otherwise you got an Overfull hbox warning.

\documentclass[11pt]{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\usepackage{float}
\usepackage{subcaption}
\captionsetup[figure]{justification=raggedright,
    singlelinecheck=false,
    format=hang,
    font=small,labelfont=bf, skip=5pt} %default=10pt
\captionsetup[subfigure]{
    justification=raggedright,
    singlelinecheck=false,
    format=hang,
    belowskip=6pt,
    font=small,labelfont=bf, skip=5pt
}


%Color definitions
\definecolor{green}{RGB}{0, 102, 0}
\definecolor{blue1}{RGB}{0, 125, 255}
\definecolor{blue2}{RGB}{0, 102, 204}
\definecolor{blue3}{RGB}{0, 76, 153}
\definecolor{blue4}{RGB}{0, 51, 102}

\begin{document}
    \section{Bonus Potential - Side by Side}
\begin{figure}[H]\centering
    \begin{subfigure}[t]{.49\linewidth} 
        \begin{tikzpicture}[scale=.7] 
        \begin{axis}[
        xlabel={Bonus Potential (bn)},
        ylabel={Frequency},     
        xmin=0, xmax=600,
        ymin=0, ymax=80,
        xtick={0,100, 200,300,400,500,600},
        ytick={0,10,20,30,40,50,60,70,80},
        xtick pos=bottom,ytick pos=left,      
        legend pos=north west,
        legend style={font=\tiny}]
        \legend{-20\%, -10\%, 0\%*, +10\%, +20\%},
        \addplot[color=blue1, style={line width=0.7pt},smooth]
        coordinates {
            (120,0)
            (180,0)
            (240,39)
            (300,55)
            (360,6)
            (420,0)
        };       
        \addplot[color=blue2,style={line width=0.8pt}, smooth]
        coordinates {
            (120,0)
            (180,1)
            (240,30)
            (300,59)
            (360,9)
            (420,1)
            (480,0)
        };   
        \addplot[color=green,style={line width=0.9pt}, smooth]
        coordinates {
            (120,0)
            (180,5.8)
            (240,59.8)
            (300,34.2)
            (360,0.2)
            (420,0)
        };  
        \addplot[color=blue3,style={line width=0.9pt}, smooth]
        coordinates {
            (120,0)
            (180,1)
            (240,31)
            (300,62)
            (360,6)
            (420,0)
        };   
        \addplot[color=blue4,style={line width=1pt}, smooth]
        coordinates {
            (120,0)
            (180,1)
            (240,34)
            (300,52)
            (360,13)
            (420,0)
        };        
        \end{axis}  
        \end{tikzpicture}   
        \caption{Minimum Variance\label{Longminvar}}    
    \end{subfigure}
    \begin{subfigure}[t]{.49\linewidth} 
        \begin{tikzpicture}[scale=.7] 
        \begin{axis}[
        xlabel={Bonus Potential (bn)},
        ylabel={Frequency},     
        xmin=0, xmax=600,
        ymin=0, ymax=80,
        xtick={0,100, 200,300,400,500,600},
        ytick={0,10,20,30,40,50,60,70,80},
        xtick pos=bottom,ytick pos=left,      
        legend pos=north west,
        legend style={font=\tiny}]
        \legend{-20\%, -10\%, 0\%*, +10\%, +20\%},
        \addplot[color=blue1, style={line width=0.7pt},smooth]
        coordinates {
            (180,0)
            (240,4)
            (300,35)
            (360,51)
            (420,10)
            (480,0)
        };       
        \addplot[color=blue2,style={line width=0.8pt}, smooth]
        coordinates {
            (180,0)
            (240,1)
            (300,31)
            (360,49)
            (420,18)
            (480,1)
            (540,0)
        };   
        \addplot[color=green,style={line width=1pt}, smooth]
        coordinates {
            (180,0)
            (240,10.5)
            (300,56.4)
            (360,32.5)
            (420,0.6)
            (480,0)
        };  
        \addplot[color=blue3,style={line width=0.9pt}, smooth]
        coordinates {
            (180,0)
            (240,31)
            (300,53)
            (360,16)
            (420,0)
        };   
        \addplot[color=blue4,style={line width=1pt}, smooth]
        coordinates {
            (180,0)
            (240,1)
            (300,33)
            (360,43)
            (420,23)
            (480,0)
        };        
        \end{axis}  
        \end{tikzpicture}   
        \caption{Tangency Portfolio\label{Longtangport}}    
    \end{subfigure}

    \begin{subfigure}[t]{.49\linewidth}  
        \begin{tikzpicture}[scale=.7] 
        \begin{axis}[
        xlabel={Bonus Potential (bn)},
        ylabel={Frequency},     
        xmin=0, xmax=600,
        ymin=0, ymax=80,
        xtick={0,100, 200,300,400,500,600},
        ytick={0,10,20,30,40,50,60,70,80},
        xtick pos=bottom,ytick pos=left,      
        legend pos=north west,
        legend style={font=\tiny}]
        \legend{-20\%, -10\%, 0\%*, +10\%, +20\%},
        \addplot[color=blue1, style={line width=0.7pt},smooth]
        coordinates {
            (180,0)
            (240,31)
            (300,53)
            (360,16)
            (420,0)
        };       
        \addplot[color=blue2,style={line width=0.8pt}, smooth]
        coordinates {
            (180,0)
            (240,37)
            (300,45)
            (360,17)
            (420,1)
            (480,0)
        };   
        \addplot[color=green,style={line width=0.9pt}, smooth]
        coordinates {
            (120,0)
            (180,3.3)
            (240,50)
            (300,46.3)
            (360,0.4)
            (420,0)
        };  
        \addplot[color=blue3,style={line width=0.9pt}, smooth]
        coordinates {
            (180,0)
            (240,31)
            (300,53)
            (360,16)
            (420,0)
        };   
        \addplot[color=blue4,style={line width=1pt}, smooth]
        coordinates {
            (180,0)
            (240,29)
            (300,55)
            (360,16)
            (420,0)
        };        
        \end{axis}  
        \end{tikzpicture}  
        \caption{Sortino\label{Longsort}}     
    \end{subfigure}
    \begin{subfigure}[t]{.49\linewidth} 
        \begin{tikzpicture}[scale=.7] 
        \begin{axis}[
        xlabel={Bonus Potential (bn)},
        ylabel={Frequency},     
        xmin=0, xmax=600,
        ymin=0, ymax=80,
        xtick={0,100, 200,300,400,500,600},
        ytick={0,10,20,30,40,50,60,70,80},
        xtick pos=bottom,ytick pos=left,      
        legend pos=north west,
        legend style={font=\tiny}]
        \legend{-20\%, -10\%, 0\%*, +10\%, +20\%},
        \addplot[color=blue1, style={line width=0.7pt},smooth]
        coordinates {
            (180,0)
            (240,4)
            (300,29)
            (360,49)
            (420,18)
            (480,0)
        };       
        \addplot[color=blue2,style={line width=0.8pt}, smooth]
        coordinates {
            (180,0)
            (240,1)
            (300,27)
            (360,45)
            (420,26)
            (480,1)
            (540,0)
        };   
        \addplot[color=green,style={line width=0.9pt}, smooth]
        coordinates {
            (180,0)
            (240,9.7)
            (300,47.8)
            (360,41.4)
            (420,1.1)
            (480,0)
        };  
        \addplot[color=blue3,style={line width=0.9pt}, smooth]
        coordinates {
            (180,0)
            (240,1)
            (300,34)
            (360,48)
            (420,17)
            (480,0)
        };   
        \addplot[color=blue4,style={line width=1pt}, smooth]
        coordinates {
            (180,0)
            (240,1)
            (300,33)
            (360,43)
            (420,23)
            (480,0)
        };        
        \end{axis}  
        \end{tikzpicture}   
        \caption{Risk Longevity\label{Longrisk}}    
    \end{subfigure}
    \caption{Longevity\label{Long}}
\end{figure}
\end{document}

enter image description here

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.