2

I observed the following behavior when plotting a simple axis-diagram in a tikz + beamer document depending on whether 'remember picture,overlay' is used or not.

The following code

\documentclass{beamer}

\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{positioning}

\begin{document}
\begin{frame}

\begin{tikzpicture}



\begin{axis}[
at={(current page.center)},
height = 12em, width = 12em,
axis lines = middle,
enlargelimits = true,
xmin = 0, xmax = 2, ymin = 0, ymax = 2,
xlabel = {$X_1$},
ylabel = {$X_2$},
x label style={at={(current axis.right of origin)},anchor=north},
y label style={at={(current axis.above origin)},anchor=east},
]

\draw[dashed,gray] (axis cs:1,0) -- (axis cs:1,2);
\draw[dashed,gray] (axis cs:0,1) -- (axis cs:1,1);

\end{axis}

\end{tikzpicture}
\end{frame}
\end{document}

gives correct axis-label positioning

However, when using 'remember picture,overlay' the positioning of the axis labels gets lost. The code:

\documentclass{beamer}

\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{positioning}

\begin{document}
\begin{frame}

\begin{tikzpicture}[remember picture,overlay]



\begin{axis}[
at={(current page.center)},
height = 12em, width = 12em,
axis lines = middle,
enlargelimits = true,
xmin = 0, xmax = 2, ymin = 0, ymax = 2,
xlabel = {$X_1$},
ylabel = {$X_2$},
x label style={at={(current axis.right of origin)},anchor=north},
y label style={at={(current axis.above origin)},anchor=east},
]

\draw[dashed,gray] (axis cs:1,0) -- (axis cs:1,2);
\draw[dashed,gray] (axis cs:0,1) -- (axis cs:1,1);

\end{axis}

\end{tikzpicture}
\end{frame}
\end{document}

it produces: incorrect placement

Note, the the axis-positioning on the frame is not the problem (I want to put it relative to the center of the frame), but I think that the axis labels should stick to the axis. At least this what I would like to obtain.

Any help is welcome! Thank you in advance!

0

1 Answer 1

1

You can use relative coordinates to place the axis labels correctly.

x label style={at={(1,0)},anchor=north},
y label style={at={(0,1)},anchor=east},

enter image description here

\documentclass{beamer}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{positioning}

\begin{document}
\begin{frame}

\begin{tikzpicture}[remember picture,overlay]
\begin{axis}[at={(current page.center)},
height = 12em, width = 12em,
axis lines = middle,
enlargelimits = true,
xmin = 0, xmax = 2, ymin = 0, ymax = 2,
xlabel = {$X_1$}, ylabel = {$X_2$},
x label style={at={(1,0)},anchor=north},
y label style={at={(0,1)},anchor=east},
]

\draw[dashed,gray] (1,0) -- (1,2);
\draw[dashed,gray] (0,1) -- (1,1);

\end{axis}
\end{tikzpicture}
\end{frame}
\end{document}
3
  • Thank you very much, indeed! This is one way to do it, although I don't understand why the (current axis.right of origin) syntax is not working. Seems to me that current axis is not moved by virtue of remember picture,overlay. Oct 30, 2019 at 10:14
  • @ThomasHilger You won't have that problem if you remove at={(current page.center)},.
    – nidhin
    Oct 30, 2019 at 10:26
  • Sure, but then I wuold have to take different measures for my placement. Nov 5, 2019 at 17:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .