1

The question is, how to vertically align the label to the middle of the y-axis. It seems that the code above first rotate the label and then move it above. The complete example is pasted below.

The code in question is:

\node[rotate=90, above=1] at (y axis mid) {long label};

enter image description here

\begin{tikzpicture}[scale=0.6]
\draw[help lines] (0,0) grid[xstep=1.5,ystep=1] (6,6);

% Axis
\draw[->,>=latex'] (0,0) -- coordinate (x axis mid) (6.5,0);
\draw[->,>=latex'] (0,0) -- coordinate (y axis mid) (0,6.5);

% Labels
\node[below=0.2] at (x axis mid) {long label};
\node[rotate=90,above=1] at (y axis mid) {long label};

\draw[red,very thick] (0,0) -- (0,3) -- (3,3) -- (3,6) -- (6,6);
\end{tikzpicture}
  • 1
    change above=1 to yshift=10pt will center the y label. – Jesse Jan 8 '14 at 11:55
4

Easiest is to put the node while drawing axes:

\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{arrows}
\begin{document}
\begin{tikzpicture}[scale=0.6]
\draw[help lines] (0,0) grid[xstep=1.5,ystep=1] (6,6);
\draw[->,>=latex'] (0,0) -- node[pos=0.5,below,rotate=0]{long label} (6.5,0);
\draw[->,>=latex'] (0,0) -- node[pos=0.5,above,rotate=90]{long label} (0,6.5);
\draw[red,very thick] (0,0) -- (0,3) -- (3,3) -- (3,6) -- (6,6);
\end{tikzpicture}
\end{document}

enter image description here

You can control the spacing and distance (between axis and label) by pos=<dimen> and above/below=<dimen> respectively.

2

Use above alone. Here yshift==xx works well too.

enter image description here

Code

\documentclass{article}
\usepackage[margin=1cm]{geometry}
\usepackage{tikz}
\usetikzlibrary{fit,calc,arrows,positioning}
\begin{document}

\begin{tikzpicture}[scale=0.6]
\draw[help lines] (0,0) grid[xstep=1.5,ystep=1] (6,6);
% Axis
\draw[->,>=latex'] (0,0) -- coordinate (x axis mid) (6.5,0);
\draw[->,>=latex'] (0,0) -- coordinate (y axis mid) (0,6.5);
% Labels
\node[below=0.2] at (x axis mid) {long label};
\node[rotate=90,yshift=10pt] at (y axis mid) {long label}; % Or use above alone.

\draw[red,very thick] (0,0) -- (0,3) -- (3,3) -- (3,6) -- (6,6);
\end{tikzpicture} 
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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