[Tex/LaTex] Pgfplots: Legend with multiple columns and rows, different entry widths

legendpgfplotswidth

I have two data sets of five curves each that I want to display in one tikzpicture. The five curves of the first data set are solid lines, the five curves of the second data set are dashed.
In the legend, I want five entries for the curves (marks only) and two extra to distinguish between the data sets (lines only). Preferably the five curve entries get displayed in one row and the data set entries in a second row. If I do this like my code shows, the the first two columns of BOTH rows are automatically adjusted.

This looks ugly. Is there any way to…
…separately adjust the columns width of each legend row?
…adjust the width of all columns to a fixed width (that matches the width of the longest entry)?
…display the data set entries in a second legend?

I'd also prefer to keep the legend below the plot. Creating in east (outside) of the plot solves the problem but also results in a non-centered plot.

Thanks in advance.

\documentclass{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}

\begin{document}
    \begin{tikzpicture}
    \begin{axis}
    [
    ylabel={ylabel}, 
    xlabel={xlabel},  
    xmin=0, 
    xmax=120, 
    ymin=0, 
    ymax=0.2,
    legend columns = 5,
    legend style = {at={(0.5, -0.23)}, anchor=north, inner sep=3pt, style={column sep=0.15cm}},       %vorher: at={(1.3, 1)}
    legend cell align=left,
    ticklabel style={
        /pgf/number format/.cd,
        fixed,
        use comma,
    }
    ]


    \addlegendimage{black, only marks, mark=square} % or mark=none?
    \addlegendentry{Entry1}

    \addlegendimage{red, only marks, mark=asterisk}
    \addlegendentry{Entry2}

    \addlegendimage{orange, only marks, mark=triangle}
    \addlegendentry{Entry3}

    \addlegendimage{green, only marks, mark=diamond}
    \addlegendentry{Entry4}

    \addlegendimage{blue, only marks, mark=o}
    \addlegendentry{Entry5}

    \addlegendimage{black, line legend}
    \addlegendentry{AlternativeEntry1}

    \addlegendimage{black, line legend, dashed}
    \addlegendentry{AlternativeEntry2}

    \addplot[color=black, mark=square] coordinates {(20,0.05)(30,0.15)};
    \addplot[color=red, mark=star] coordinates {(20,0.05)(40,0.15)};
    \addplot[color=orange, mark=triangle] coordinates {(20,0.05)(50,0.15)};
    \addplot[color=green, mark=diamond] coordinates {(20,0.05)(60,0.15)};
    \addplot[color=blue, mark=o] coordinates {(20,0.05)(70,0.15)};

    \addplot[color=black, mark=square, dashed, mark options={solid}] coordinates {(60,0.05)(30,0.18)};
    \addplot[color=red, mark=star, dashed, mark options={solid}] coordinates {(60,0.05)(40,0.18)};
    \addplot[color=orange, mark=triangle, dashed, mark options={solid}] coordinates {(60,0.05)(50,0.18)};
    \addplot[color=green, mark=diamond, dashed, mark options={solid}] coordinates {(60,0.05)(60,0.18)};
    \addplot[color=blue, mark=o, dashed, mark options={solid}] coordinates {(60,0.05)(70,0.18)};

    \end{axis}
    \end{tikzpicture}

\end{document}

Two data sets with five curves each

Best Answer

This is an ad how way of wasting less space in your specific use case: add an empty column and pretend the long entries have zero width.

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
    \begin{tikzpicture}
    \begin{axis}
    [
    ylabel={ylabel}, 
    xlabel={xlabel},  
    xmin=0, 
    xmax=120, 
    ymin=0, 
    ymax=0.2,
    legend columns = 5,
    legend style = {at={(0.5, -0.23)}, anchor=north, inner sep=3pt, style={column sep=0.15cm}},       %vorher: at={(1.3, 1)}
    legend cell align=left,
    ticklabel style={
        /pgf/number format/.cd,
        fixed,
        use comma,
    }
    ]


    \addlegendimage{black, only marks, mark=square} % or mark=none?
    \addlegendentry{Entry1}

    \addlegendimage{red, only marks, mark=asterisk}
    \addlegendentry{Entry2}

    \addlegendimage{orange, only marks, mark=triangle}
    \addlegendentry{Entry3}

    \addlegendimage{green, only marks, mark=diamond}
    \addlegendentry{Entry4}

    \addlegendimage{blue, only marks, mark=o}
    \addlegendentry{Entry5}

    \addlegendimage{black, line legend}
    \addlegendentry{\makebox[0pt][l]{AlternativeEntry1}}

    \addlegendimage{empty legend}
    \addlegendentry{}
    \addlegendimage{black, line legend, dashed}
    \addlegendentry{\makebox[0pt][l]{AlternativeEntry2}}

    \addplot[color=black, mark=square] coordinates {(20,0.05)(30,0.15)};
    \addplot[color=red, mark=star] coordinates {(20,0.05)(40,0.15)};
    \addplot[color=orange, mark=triangle] coordinates {(20,0.05)(50,0.15)};
    \addplot[color=green, mark=diamond] coordinates {(20,0.05)(60,0.15)};
    \addplot[color=blue, mark=o] coordinates {(20,0.05)(70,0.15)};

    \addplot[color=black, mark=square, dashed, mark options={solid}] coordinates {(60,0.05)(30,0.18)};
    \addplot[color=red, mark=star, dashed, mark options={solid}] coordinates {(60,0.05)(40,0.18)};
    \addplot[color=orange, mark=triangle, dashed, mark options={solid}] coordinates {(60,0.05)(50,0.18)};
    \addplot[color=green, mark=diamond, dashed, mark options={solid}] coordinates {(60,0.05)(60,0.18)};
    \addplot[color=blue, mark=o, dashed, mark options={solid}] coordinates {(60,0.05)(70,0.18)};

    \end{axis}
    \end{tikzpicture}
\end{document}

enter image description here