# Spacing bars in ybar

I have several problems with this diagram:

1. I am trying to create a template plot that I can use several times with different amount of bars. To simplify that I would like to define a fix bar width and a fix space between the bars. The x-axis should change it length depending on the amount of bars. The y-axis should keep the same hight in every diagram.
2. Is there a way to simplify the \node [above] at (axis cs: A,1) {100\%}; expression, so I don’t have to type in the value manually
3. I would like the x label to automatically adjust to the length of the x-axis
4. I would like to delete the little line at the top of the arrow at the y-axis

\documentclass[a4paper,twoside,11pt]{scrreprt}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{positioning}
\usetikzlibrary{patterns}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
every axis plot post/.style={/pgf/number format/fixed},
ybar=5pt,
bar width=12pt,
x=4cm,
ymin=0,
xtick=data,
xlabel=a label that is longer than the x-axis and needs an automatic break,
enlarge x limits=10,
symbolic x coords={A, B},
point meta={y*100}, %y-Werte mal 100 für Prozent
yticklabel={\pgfmathparse{\tick*100}\pgfmathprintnumber{\pgfmathresult}\%},
axis lines*=left,
axis x line*=bottom, axis y line=left,
enlarge x limits=auto,
clip=false
]
\addplot [draw=black, fill=white, error bars/.cd, y dir=both, y explicit] coordinates{(A,1) (B,.155)+-(.038,.038)};
\node [above] at (axis cs:  A,1) {100\%};
\node (a) [above] at (axis cs:  B,.193) {15,5\%};
\node [above=-0.2cm of a] {*};
\end{axis}
\end{tikzpicture}
\end{document}


1. To get a fixed distance between the centers of the bars, set x=<distance>. To set the width of the bars, set bar width=<distance>. To get a fixed amount of space between the first bar and the left edge of the plot, and between the last bar and the right edge of the plot, set enlarge x limits={abs=<distance>}.
2. To label the bars, set nodes near coords={\pgfmathprintnumber{\pgfplotspointmeta}\,\%},
3. I can't think of an elegant way to do this off the top of my head. Maybe you could open a new question for this?
4. Set axis lines*=left (with the asterisk) to switch off the arrow head.

\documentclass[a4paper,twoside,11pt]{scrreprt}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{positioning}
\usetikzlibrary{patterns}
\begin{document}
\makeatletter
\begin{tikzpicture}
\begin{axis}[
ybar,
bar width=1cm, % Width of the bar
x=2cm, % Distance between the centers of the bars
enlarge x limits={abs=1cm}, % The distance between the center of the first bar and the left edge
enlarge y limits=false,
ymin=0,
xtick=data,
xlabel=a label that is longer than the x-axis and needs an automatic break,
symbolic x coords={A, B},
point meta={y*100}, %y-Werte mal 100 für Prozent
yticklabel={\pgfmathparse{\tick*100}\pgfmathprintnumber{\pgfmathresult}\%},
axis lines*=left,
clip=false
]
draw=black,
fill=white,
nodes near coords={\pgfmathprintnumber{\pgfplotspointmeta}\,\%},
error bars/.cd,
y dir=both,
y explicit
] coordinates{(A,1) (B,.155)+-(.038,.038)};
\pgfplotsextra{
\pgfmathfloattofixed{\pgfplots@data@xmax}
\pgfplotsset{xlabel style=1cm}
}
\end{axis}
\end{tikzpicture}
\end{document}