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

1
  • Related (duplicate?): number format in pgfplots axis, which also explains how to change the thousands separator to something other than a comma.
    – Jake
    Mar 11, 2015 at 9:13

1 Answer 1

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} 
5
  • 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, 2015 at 8:51
  • Thanks for the hint, I forgot that indeed. I will update the screen shot
    – user31729
    Mar 11, 2015 at 9: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, 2015 at 9: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, 2015 at 9:12
  • @yo': Thanks, I changed the old answer to use icomma
    – user31729
    Mar 11, 2015 at 9:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .