LaTeX forum ⇒ Graphics, Figures & TablesSmall glitch with a TikZ graphics Topic is solved

Information and discussion about graphics, figures & tables in LaTeX documents.
User avatar
Cham
Posts: 697
Joined: Sat Apr 02, 2011 4:06 pm

Small glitch with a TikZ graphics  Topic is solved

Postby Cham » Mon Sep 18, 2017 2:22 am

I need to fix a simple number shown on the main axis of the following graphics :

  1. \documentclass[10pt,oneside]{scrartcl}
  2. \usepackage[T1]{fontenc}
  3. \usepackage[utf8]{inputenc}
  4. \usepackage{amsmath}
  5. \usepackage{amsfonts}
  6. \usepackage{amssymb}
  7. \usepackage{mathtools}
  8. \usepackage{pgfplots}
  9. \pgfplotsset{width=7cm,every tick/.style={black}}
  10. \usepackage{graphicx}
  11.  
  12. \begin{document}
  13.  
  14. \begin{center}
  15. \begin{tikzpicture}
  16. \begin{axis}[
  17. scale only axis=true,
  18. width=10cm,
  19. height=2cm,
  20. grid=none,
  21. minor tick num=1,
  22. %xtick align=center,
  23. xlabel=$x$,
  24. ytick=\empty,
  25. title={},
  26. xmin=1.48,
  27. xmax=1.54,
  28. ymin=-1,
  29. ymax=3,
  30. axis x line = bottom,
  31. axis y line = none,
  32. legend style={at={(1, 0.45)},anchor=west,font=\footnotesize,draw=black},
  33. ]
  34. \addplot+[color=black,mark options={mark=*,mark size=2pt,fill=gray,scale=1},error bars,x dir=both,x explicit]
  35. coordinates {
  36. (1.51, 1.25) +- (0.02, 0)
  37. };
  38. \addlegendentry{$a$};
  39. \addplot+[color=black,mark options={mark=square*,mark size=2pt,fill=gray,scale=1},error bars,x dir=both,x explicit]
  40. coordinates {
  41. (1.504, 0.25) +- (0.003, 0)
  42. };
  43. \addlegendentry{$b$};
  44. \end{axis}
  45. \end{tikzpicture}
  46. \end{center}
  47.  
  48. \end{document}


Here's a preview of what that code is doing :
diagram.jpg
diagram.jpg (11.11 KiB) Viewed 173 times


The number indicated in red should read 1.50 instead of 1.5. How can I fix this tiny yet insulting glitch ?

mas
Posts: 198
Joined: Thu Dec 04, 2008 4:39 am

Postby mas » Mon Sep 18, 2017 3:54 am

Added this for the axis options
  1. xticklabel style={
  2. /pgf/number format/precision=2,
  3. /pgf/number format/fixed zerofill}

I got this:
x.png
x.png (4.29 KiB) Viewed 169 times

OS: Debian/GNU Linux; LaTeX System : TeXLive; Editor : Vim

User avatar
Cham
Posts: 697
Joined: Sat Apr 02, 2011 4:06 pm

Postby Cham » Mon Sep 18, 2017 4:31 am

WOW ! :shock:

It's working, but I would have never found this by myself ! :?

Thanks a lot !

User avatar
Cham
Posts: 697
Joined: Sat Apr 02, 2011 4:06 pm

Postby Cham » Mon Sep 18, 2017 2:33 pm

Before I mark this problem as solved, is there another way (simpler ?) in doing this ?

mas
Posts: 198
Joined: Thu Dec 04, 2008 4:39 am

Postby mas » Mon Sep 18, 2017 2:52 pm

Cham wrote:It's working, but I would have never found this by myself ! :?

When all else fails, read the manual :D It is on page 23 of the pgfplots manual under the heading "Satisfying Different Tastes".

OS: Debian/GNU Linux; LaTeX System : TeXLive; Editor : Vim

User avatar
Cham
Posts: 697
Joined: Sat Apr 02, 2011 4:06 pm

Postby Cham » Tue Sep 19, 2017 11:11 pm

So there is no other way in doing this ? Should I mark the thread as "solved"?


Return to “Graphics, Figures & Tables”

Who is online

Users browsing this forum: Bing [Bot] and 10 guests