TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Consider the following MWE

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{
    compat=1.12,
    stdaxis/.style={
        ylabel style={at={(ticklabel cs:1.06)},anchor=west,rotate=270},
        }
    }
\begin{document}
\begin{tikzpicture}
    \begin{axis}[stdaxis,ylabel=$f(x)$,xlabel=$x$]
    \addplot {x^2};
    \end{axis}
\end{tikzpicture}
\end{document}

produced output

This is exactly what I want. My problem is that when I use the same stdaxis style for another picture with a different height, the y-axis label "f(x)" gets too high or too low. To circumvent this, I would like to use an absolute positioning and change the style to something like ylabel style={at={(ticklabel cs:1.0+5mm)},anchor=west,rotate=270}

How is this possible?

share|improve this question
up vote 4 down vote accepted

You can achieve this with coordinate calculations using the TikZ library calc (cf. section 13.5 of the PGF/TikZ manual):

\documentclass{article}
\usepackage{pgfplots}
\usetikzlibrary{calc}
\pgfplotsset{
    compat=1.12,
    stdaxis/.style={
        ylabel style={at={($(ticklabel cs:1.0)+(0mm,5mm)$)},anchor=west,rotate=270},
        }
    }
\begin{document}
\begin{tikzpicture}
    \begin{axis}[stdaxis,ylabel=$f(x)$,xlabel=$x$]
    \addplot {x^2};
    \end{axis}
\end{tikzpicture}
\end{document}

example plot, with y label 5mm above the upper left corner of the axis box

share|improve this answer
    
I almost tried this, but my mistake was that I assumed, the second coordinate should be one-dimensional, too (as is the axis coordinate). Thanks! Note: esdd's answer produces exactly the same output – riddleculous Mar 27 at 0:20

Use yshift=5mm after rotate=270:

enter image description here

Code:

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{
    compat=1.12,
    stdaxis/.style={
            ylabel style={at={(ticklabel cs:1)},
            anchor=west,
            rotate=270,
            yshift=5mm% <-
            },
        }
    }
\begin{document}
\begin{tikzpicture}
    \begin{axis}[stdaxis,ylabel=$f(x)$,xlabel=$x$]
    \addplot {x^2};
    \end{axis}
\end{tikzpicture}

\bigskip
\begin{tikzpicture}
    \begin{axis}[stdaxis,height=10cm,ylabel=$f(x)$,xlabel=$x$]
    \addplot {x^2};
    \end{axis}
\end{tikzpicture}
\end{document}
share|improve this answer
    
thanks for clarifying the yshift position! So far I didn't the logic behind this yet, I tried similar things but not after the rotate. As diabonas' anser was a bit faster and seems better understandable to me, I accepted that one, although yours produces exactly the same result and does not even need a further library loaded – riddleculous Mar 27 at 0:24

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.