使用以下代码从答案这个问题,
如何从一个节点到另一个节点绘制红线,例如从 -3 到 3 个位置
\documentclass{beamer}
\beamertemplatenavigationsymbolsempty
\usepackage{verbatim}
\usepackage{tikz}
\usetikzlibrary{arrows, arrows.meta}
\usepackage{pgfplots}
\begin{document}
\begin{frame}[t]
\frametitle{che}
\begin{tikzpicture}[scale=.86, transform shape]
\draw [thick](0,0) -- (9.,0);
\begin{scope}[xshift=-1.cm, yshift=0cm]
\foreach[count=\j] \i in {-4,...,4}
\draw[very thick] (\j*1.134,.2) -- ++(0,-.4) node[yshift=-.35cm]{\i}coordinate(\i);
\end{scope}
\draw [red, ultra thick] (0,2.4) node [xshift=1.2cm, yshift=.26cm]{observations} -- (9,2.4cm);
\draw [red, ultra thick, -latex'] (0,2.4)--(0,.2);
\draw [red, ultra thick, -latex'] (9,2.4)--(9,.2);
\end{tikzpicture}
\end{frame}
\end{document}
答案1
我会一次性画出这个东西。
\documentclass{beamer}
\beamertemplatenavigationsymbolsempty
\usepackage{verbatim}
\usepackage{tikz}
\usetikzlibrary{arrows, arrows.meta}
\usepackage{pgfplots}
\begin{document}
\begin{frame}[t]
\frametitle{che}
\begin{tikzpicture}[scale=.86, transform shape]
\draw [thick](0,0) -- (9.,0);
\begin{scope}[xshift=-1.cm, yshift=0cm]
\foreach[count=\j] \i in {-4,...,4}
\draw[very thick] (\j*1.134,.2) -- ++(0,-.4) node[yshift=-.35cm]{\i}coordinate(\i);
\end{scope}
\draw [red, ultra thick, latex'-latex'] ([yshift=0.6cm]-3)-- ++ (0,2) -|
node[pos=0.03,above,anchor=south west]{observations} ([yshift=0.6cm]3);
\end{tikzpicture}
\end{frame}
\end{document}