9

This MWE:

\documentclass{article}
% translate with >> pdflatex -shell-escape <file>

% This file is an extract of the PGFPLOTS manual, copyright by Christian Feuersaenger.
% 
% Feel free to use it as long as you cite the pgfplots manual properly.
%
% See
%   http://pgfplots.sourceforge.net/pgfplots.pdf
% for the complete manual.
%
% Any required input files (for <plot table> or <plot file> or the table package) can be downloaded
% at
% http://www.ctan.org/tex-archive/graphics/pgf/contrib/pgfplots/doc/latex/
% and
% http://www.ctan.org/tex-archive/graphics/pgf/contrib/pgfplots/doc/latex/plotdata/

\usepackage{pgfplots}
\pgfplotsset{compat=newest}

\pagestyle{empty}

\usepgfplotslibrary{units}

\begin{document}
\begin{tikzpicture}
  \begin{axis}[change x base,
    x SI prefix=kilo,x unit=m,
    y SI prefix=milli,y unit=N,
    xlabel=Distance,ylabel=Force]
    \addplot coordinates {
        (1000,1)
        (2000,1.1)
        (3000,1.2)
        (4000,1.3)
    };
  \end{axis}
\end{tikzpicture}
\end{document}

results in units set in square brackets. This conflicts to the SI-brochure 8 and the German standard DIN 1313.

How can I switch that off or change it to "/unit" or "+in+unit"? I am not able to report that on sourceforge which is a pity as this wrong unit formatting is getting more and more popular.

If Mr. Feuersänger is reading here on TEX.SX, I am having this feature requests regarding the units:

  • never use brackets at all, but slash or "in" (Edit: for slash notation round brackets for divided units could be useful as mentioned in the comments. E.g. $a$/(m/s^2))
  • possibility to set unit after the symbol (axis label) or between the last two tick labels (or in place of the second last ticks label if to less space)
  • allow siunitx-syntax
  • automatically set angle units (°, ' and '') and time units (^h, ^min and ^s) (not to be confused with time period units (a, h, min and s)) directly next to each tick label
  • set powers of ten or units like %, or ppm between the last two tick labels
LaRiFaRi
  • 43,807
  • 3
    simply do unit markings=slash space – nickpapior Jul 31 '13 at 11:11
  • Thanks, your idea works, but it has a space in front and after the slash which are both forbidden. unit markings=slash is not working. I will search for other unit markings-commands in the manual. Still, a wrong default should be changed. – LaRiFaRi Jul 31 '13 at 11:17
  • So it should be "Force/nM"? That seems very strange. So what does your "+" mean? But you can just alter how it should be printed using the answer I provided. – nickpapior Jul 31 '13 at 11:18
  • I strongly disagree with this method. I think that's one of the most stupid standards. I'm really surprised that the standard is coming out as it is but anyway that's me. Your issues are mostly implemented already except the ticks with units in them. units library supports siunitx input. siunitx also supports arc notation for degrees. – percusse Jul 31 '13 at 11:19
  • "Force in mN" or "\textit{F}/mN" would be what I would write. – LaRiFaRi Jul 31 '13 at 11:21
  • I agree with @percusse, I also dislike the standard I much prefer the bracketed way. Often units are shown with eV/Ang or something similar, so in the standard that would yield: "Force / eV/Ang". :) – nickpapior Jul 31 '13 at 11:21
  • So you would write the asterisk? Hmm. Each to ones own liking. :) – nickpapior Jul 31 '13 at 11:22
  • 2
    Note that the use of a slash follows from the idea that you are dividing a quantity by the unit to leave unitless values for the axes: there is a reason for the standard! – Joseph Wright Jul 31 '13 at 11:28
  • @JosephWright There is still no reason for squeezing it between the last two ticks. – percusse Jul 31 '13 at 11:29
  • @percusse Ah, that part is I agree stupid :-) – Joseph Wright Jul 31 '13 at 11:30
  • @zeroth If you refer to the asterisk in my command: I tried to set the F italic :-). @Joseph Wright exactly. I think the standard makes sense. And all brackets (), [] and {} are reserved for other meanings. – LaRiFaRi Jul 31 '13 at 11:31
  • @JosephWright that is a good explanation, however, the reading of the label with multiple division marks is rather "ugly" in my opinion. :) How should I parenthesise those units? (rhetorical question... :) ) – nickpapior Jul 31 '13 at 11:31
  • 2
    @zeroth For multiple division I use brackets on the divisor: I find that OK but I can see that not everyone does. You write a package to support units, you get some very definite ideas about how units work :-) – Joseph Wright Jul 31 '13 at 11:32
  • @percusse OK, that would be just an alternative option to implement all the standard. I don't use that often but it can look beautiful. Well, as everyone likes. For powers of ten I would like that feature (but I will search the manual for that...) – LaRiFaRi Jul 31 '13 at 11:33
  • 1
    @LaRiFaRi: The part with the ticks isn't implemented, there was a question about this recently (http://tex.stackexchange.com/questions/123977/axis-labels-according-to-din461). Generally though, I think that "forbidden" and "wrong" are rather strong words for this discussion: These are conventions, not laws. The goal is to communicate information, and for different audiences, different ways of presenting information can be more suitable. – Jake Jul 31 '13 at 11:47
  • @Jake Unfortunately, it is the law in the industry especially if you are preparing a project proposal for competition. – percusse Jul 31 '13 at 11:52
  • @percusse: Okay, sorry, misphrased that: "In many applications, these are conventions, not laws". – Jake Jul 31 '13 at 11:54
  • @jake You are right about "rather strong words". Sorry. But rules make a lot of things easier (less options). E.g. a slash shouldn't be followed by a space... Isn't that like a law in typesetting? – LaRiFaRi Jul 31 '13 at 12:08
  • @LaRiFaRi: No, not even that is a "law": Different style guides recommend different things. For example, it is frequently recommended to use spaces around the slash when it separates multi word objects. – Jake Jul 31 '13 at 12:14

1 Answers1

10

You have the possibility to alter the way it looks. The units library is not fully implemented, and will probably never fully be. Attaching units can be a rather integrate matter.

However you can accomplish your request by:

\begin{tikzpicture}
  \begin{axis}[change x base,
    x SI prefix=kilo,x unit=m,
    y SI prefix=milli,y unit=N,
    unit markings=slash space,
    % Or do it by your self...
    % unit marking pre={\text{in }}, % requires amsmath
    % unit marking post={},
    xlabel=Distance,ylabel=Force]
    \addplot coordinates {
        (1000,1)
        (2000,1.1)
        (3000,1.2)
        (4000,1.3)
    };
  \end{axis}
\end{tikzpicture}

which produces (both examples shown):

enter image description here

EDIT: per the comments I have added a better way to make what the op would like. It can be accommodated by:

unit marking pre={\!\!/},
unit marking post={},
ylabel=$F$

where the negative space \!\! should gobble one \space (I can never remember if this is exactly so or not, please fill in the gaps if you know the exact negative space to insert).
This should produce what the OP is asking for.

nickpapior
  • 17,275
  • could you try to write $F$/mN or $F/si{\milli\Newton}$ and I'll mark it as an answer. Thanks. – LaRiFaRi Jul 31 '13 at 11:27
  • ok, thats quite tricky, you may try $F/\si{\milli\newton}$ :-) . Sorry for the typo. – LaRiFaRi Jul 31 '13 at 11:36
  • 1
    @LaRiFaRi Remove the y unit prefix and use y unit={\si{F\per\milli\newton}}, then siunitx will figure out what to do with the per whether fraction of / symbol. – percusse Jul 31 '13 at 11:50
  • @LaRiFaRi I was just away, I think percusse's suggestion is the best way to get around it. I am not sure why you want mN to be siunitxified and F not? – nickpapior Jul 31 '13 at 11:52
  • Because F is the symbol, which gets divided through its unit. So the result would be: unit marking pre={}, unit marking post={}, y unit={\si{$F$\per\milli\newton}} which doesn't really look like intuitive writing. The F shouldn't be inside an unit argument of the axis. – LaRiFaRi Jul 31 '13 at 11:58
  • Ahh, sorry, I was just thinking that you wanted F inside the unit. My recommendation, don't use the library if you want to do it like that. The easiest thing is to "hack" the library to suit your needs. – nickpapior Jul 31 '13 at 12:00
  • OK, how disappointing. Could you please add my last comment to your answer as a work around? At least that gives my desired result. ylabel=Force can be taken away or left where it is and both versions seem to look correct. Thanks. – LaRiFaRi Jul 31 '13 at 12:11
  • OK, but that doesn't work for divided units I think. Maybe the only answer is ylabel=Force $F/\si{\milli\newton}$. Not using the units-arguments makes all my other suggestions difficult to implement... – LaRiFaRi Jul 31 '13 at 12:20
  • 1
    @LaRiFaRi I have added a way which I think is a bit more clean, and portable to other units. :) – nickpapior Jul 31 '13 at 12:55