5

I have a tikz diagram with some numbers in it. But I want, taht tikz displayes "0.38" instead of "0,38" as value (it is a german document, so I need another separator). How is this possible?

\documentclass{scrbook}

\usepackage{ngerman}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
\usepackage{tikz}

\begin{document}


\begin{tikzpicture}
\begin{axis}[
    ybar,
    nodes near coords]
\addplot coordinates{ (1, 0.381)};
\end{axis}
\end{tikzpicture}

\end{document} 

Current result

SunBlack
  • 337

1 Answers1

4

This sets all decimal numbers to , usage.

Thanks to Jake's comment, there is an 'easier' way to get the comma format

\documentclass{scrbook}

\usepackage{ngerman} % Is this needed???
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
\usepackage{tikz}

\begin{document}

\pgfkeys{/pgf/number format/use comma}
\begin{tikzpicture}
\begin{axis}[
    ybar,
    nodes near coords]
\addplot coordinates{ (1, 0.381)};
\end{axis}
\end{tikzpicture}

\end{document} 

enter image description here

Older version of the code

\pgfkeys{/pgf/number format/set decimal separator={,}}

\documentclass{scrbook}

\usepackage{ngerman}
\usepackage{icomma}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
\usepackage{tikz}

\begin{document}

\pgfkeys{/pgf/number format/set decimal separator={,}}
\begin{tikzpicture}

\begin{axis}[
    ybar,
    nodes near coords]
\addplot coordinates{ (1, 0.381)};
\end{axis}
\end{tikzpicture}

\end{document} 
  • 1
    It works - thank you :). Hust as hint, if another find this thread: it is a good idea to include \usepackage{icomma} too (remove space after comma in numbers) – SunBlack Mar 10 '15 at 08:51
  • Thanks for the hint, I forgot that indeed. I will update the screen shot –  Mar 11 '15 at 09:01
  • @SunBlack It is better to use \pgfkeys{/pgf/number format/set decimal separator={\relax{,}}} IMHO, since comma has two meanings really and you need to distinguish them. Package icomma prevents this somehow. – yo' Mar 11 '15 at 09:10
  • 2
    You can achieve this without additional packages by using \pgfkeys{/pgf/number format/use comma} instead of \pgfkeys{/pgf/number format/set decimal separator={,}} – Jake Mar 11 '15 at 09:12
  • @yo': Thanks, I changed the old answer to use icomma –  Mar 11 '15 at 09:18