Graphics, Figures & TablesRemove trailing Zeros in Axis Labels

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
User avatar
svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

Remove trailing Zeros in Axis Labels

Post by svend_tveskaeg »

I've also asked this question on TeX StackExchange.

Code: Select all

\documentclass{article}
\usepackage{pst-plot}

\begin{document}
  \psset{xunit=2}
  \begin{pspicture}(3,1)
    \psaxes[Dx = 0.5]{->}(3,1)
  \end{pspicture}
\end{document}
Is it possible to get "1" and "2" instead of "1.0" and "2.0" (as with 0) as axis labels?
``In the game of chess, you can never let your adversary see your pieces.''
-- Zapp Brannigan, Futurama (season 1, episode 4)

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
User avatar
svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

Remove trailing Zeros in Axis Labels

Post by svend_tveskaeg »

Here is a solution from Marco Daniel:

Code: Select all

\documentclass{article}

\usepackage{pst-plot}

\makeatletter
\def\@LabelComma#1.#2.#3\@nil{%
  \def\pst@tempA{#1}%
  \ifx\pst@tempA\@empty\the\@zero\else#1\fi% the integer part
  \def\pst@tempA{#2}
  \ifx\pst@tempA\@empty
     \@writeDecimals{}%
  \else%
    \ifnum#2=0\relax\else%
      \@writeDecimals{#2}%
   \fi%
 \fi%
}
\makeatother

\begin{document}

\psset{xunit = 2}
\begin{pspicture}(3,1)
\psaxes[
  comma,
  Dx = 0.5
]{->}(3,1)
\end{pspicture}

\end{document}
``In the game of chess, you can never let your adversary see your pieces.''
-- Zapp Brannigan, Futurama (season 1, episode 4)
Post Reply