Nothing exciting here. I only have code to display the coordinate axes. I have a file in which displays of various functions are plotted on the Cartesian plane and displays of a pair of intersecting lines, a triangle, a parallelogram, or some other polygon is drawn on the Cartesian plane. The axes are labeled x
and y
. In the case in which functions are plotted, the specifications
xlabel style={at={(ticklabel* cs:1)},anchor=north west}
and
ylabel style={at={(ticklabel* cs:1)},anchor=south west}
are used in the axis
environment to label the axes. In the case in which lines or polygons are drawn, a node command is issued. I want the positioning of the x
and y
to be consistent.
In the following code, only the axes are drawn. I position the x
with the following commands.
\coordinate (x-label) at ($(5,0) +({1em*0.6},-0.6em)$);
\node[red] at (x-label){$x$};
I position the y
with the following commands.
\coordinate (y-label) at ($(0,5) +({1em*(2/3)},{1em*(2/3)})$);
\node[red] at (y-label){$y$};
They do not position the x
and y
exactly over the x
and y
from the axis
environment. Why is a horizontal and vertical shift of 1em*0.6
"close" to getting the right fit for x
but {1em*(2/3)
is close to getting the right fit for y
? How do I get x
and y
to be consistently positioned in this file?
\documentclass{amsart}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{tikz}
\usetikzlibrary{calc,angles,positioning,intersections,quotes}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\begin{document}
\noindent \hspace*{\fill}
\begin{tikzpicture}
\begin{axis}[width=5in,axis equal image,clip=false,
axis lines=middle,
xmin=-5,xmax=5,
ymin=-1.5,ymax=5,
restrict y to domain=-1.5:5,
xtick={\empty},ytick={\empty},
axis line style={latex-latex},
xlabel=$x$,ylabel=$y$,
xlabel style={at={(ticklabel* cs:1)},anchor=north west},
ylabel style={at={(ticklabel* cs:1)},anchor=south west}
]
\draw[latex-latex] (-5,0) -- (5,0);
\coordinate (x-label) at ($(5,0) +({1em*0.6},-0.6em)$);
\node[red] at (x-label){$x$};
\draw[latex-latex] (0,-1.5) -- (0,5);
\coordinate (y-label) at ($(0,5) +({1em*(2/3)},{1em*(2/3)})$);
\node[red] at (y-label){$y$};
\end{axis}
\end{tikzpicture}
\end{document}
Best Answer
I don't know why you want to do this particularly but you can get them consistently positioned by specifying them in the same way as you do for the
axis
environment:Something like 2/3 is always going to involve a certain imprecision but, in general, TikZ/PGF has limited precision because it is implemented in TeX.