You have two choices; which one depends very much on the application.
Remember that if you do
\newcommand{\foo}[3]{...}
then a call to \foo
should be of the form
\foo{first}{second}{third}
where each argument is braced. It's not the same as in other programming language: the syntax \foo{first,second,third}
would take first,second,third
as #1
and TeX would look further for #2
and #3
.
\documentclass{article}
\usepackage{tikz, pgfplots}
\newcommand{\myplotA}[3]{%
\begin{tikzpicture}
\begin{axis}[
xbar,
bar shift=0pt,
bar width=20pt,
xmin=0,
axis x line = none,
axis y line* = middle,
ytick={1,2,3},
tickwidth=0,
every tick/.style={draw=none},% label pos, no tick marks
yticklabels={#1,#2,#3},
]
\addplot coordinates {(2,1)};
\addplot coordinates {(5,2)};
\addplot coordinates {(4,3)};
\end{axis}
\end{tikzpicture}%
}
\newcommand{\myplotB}[1]{%
\begin{tikzpicture}
\begin{axis}[
xbar,
bar shift=0pt,
bar width=20pt,
xmin=0,
axis x line = none,
axis y line* = middle,
ytick={1,2,3},
tickwidth=0,
every tick/.style={draw=none},% label pos, no tick marks
yticklabels={#1},
]
\addplot coordinates {(2,1)};
\addplot coordinates {(5,2)};
\addplot coordinates {(4,3)};
\end{axis}
\end{tikzpicture}%
}
\begin{document}
\myplotA{L1}{L2}{L3}
\bigskip
\myplotB{L1,L2,L3}
\end{document}
As you see in the picture, the output is the same.
Best Answer
There are some circumstances in which this simple approach won't work, depending on how the command you're redefining was defined initially. See: