# How to draw horizontal(row) legend without the surronding rectangle?

I found the following code to manually draw legend, but it produces vertical(column) legend. How to draw it horizontally? I don't want surrounding rectangle also.

\documentclass{article}

\usepackage{pgfplots}

% argument #1: any options
\newenvironment{customlegend}[1][]{%
\begingroup
% inits/clears the lists (which might be populated from previous
% axes):
\csname pgfplots@init@cleared@structures\endcsname
\pgfplotsset{#1}%
}{%
% draws the legend:
\csname pgfplots@createlegend\endcsname
\endgroup
}%

% makes \addlegendimage available (typically only available within an
% axis environment):

\begin{document}

\thispagestyle{empty}

\begin{tikzpicture}
\begin{customlegend}[legend entries={$a$,$e^x$,C,$d$}]
\end{customlegend}
\end{tikzpicture}

\end{document}


Output:

-
It is tempting to work on a solution using the automatic way of drawing legends with pgfplots. Maybe you should give some more information, to understand why this (simpler) method doesn't fit your needs, details aside. –  T. Verron Mar 9 '13 at 1:02

Originally, you could use legend style={draw=none, legend columns=-1}, which would draw the legend horizontally and doesn’t have a box around it.

The draw=none part works, the legend columns key does not work in the legend style style anymore. But it does outside.

Ergo:

\begin{customlegend}[
legend columns=-1,
legend style={
draw=none,
column sep=1ex,
},
legend entries={$a$,$e^x$,C,$d$}
]


I also have used \makeatletter and \makeatother so you can use @ as a letter instead of using \csname. (See What do \makeatletter and \makeatother do?)

## Code

\documentclass[tikz]{standalone}

\usepackage{pgfplots}

% argument #1: any options
\makeatletter
\newenvironment{customlegend}[1][]{%
\begingroup
% inits/clears the lists (which might be populated from previous
% axes):
\pgfplots@init@cleared@structures
\pgfplotsset{#1}%
}{%
% draws the legend:
\pgfplots@createlegend
\endgroup
}%

% makes \addlegendimage available (typically only available within an
% axis environment):
\makeatother
\begin{document}
\begin{tikzpicture}
\begin{customlegend}[legend columns=-1,legend style={draw=none,column sep=1ex},legend entries={$a$,$e^x$,C,$d$}]