直到昨天,我才能定期使用报告的代码这个答案在两条线的交点处画一个圆。今天,完全相同的代码突然停止工作。崩溃是由选项引起的\pgfplotsset{compat=newest}
:从代码中删除它可以解决问题。我不明白为什么会这样。有人能帮我吗?请在此处查找 MWE。
\documentclass{beamer}
\usepackage{tikz,pgfplots}
\pgfplotsset{compat=newest} % <-- This generates the issue
\usetikzlibrary{intersections}
% New command to show and label intersections
\newcommand*{\ShowIntersection}[2]{
\fill
[name intersections={of=#1 and #2, name=i, total=\t}]
[draw=black,fill=red]
\foreach \s in {1,...,\t}{(i-\s) circle (2pt) node (intersection\s) {}};
}
\begin{document}
\begin{frame}
\frametitle{MWE}
\centering
\begin{tikzpicture}
\begin{axis}
\addplot [name path global=f] {-x};
\addplot [name path global=g] {0};
\ShowIntersection{f}{g}
\end{axis}
\end{tikzpicture}
\end{frame}
\end{document}
答案1
问题并不在于compat=newest
你对圆圈使用了过时的语法。如果你切换到现代语法circle[radius=2pt]
,问题就解决了。
\documentclass{beamer}
\usepackage{tikz,pgfplots}
\pgfplotsset{compat=newest} % <-- This is fine
\usetikzlibrary{intersections}
% New command to show and label intersections
\newcommand*{\ShowIntersection}[2]{
\fill
[name intersections={of=#1 and #2, name=i, total=\t}]
[draw=black,fill=red]
\foreach \s in {1,...,\t}{(i-\s) circle[radius=2pt] node (intersection\s) {}};
}
\begin{document}
\begin{frame}
\frametitle{MWE}
\centering
\begin{tikzpicture}
\begin{axis}
\addplot [name path global=f] {-x};
\addplot [name path global=g] {0};
\ShowIntersection{f}{g}
\end{axis}
\end{tikzpicture}
\end{frame}
\end{document}
当然,您也可以使用圆形节点。
\documentclass{beamer}
\usepackage{pgfplots}
\pgfplotsset{compat=newest} % <-- This works fine
\usetikzlibrary{intersections}
% New command to show and label intersections
\newcommand*{\ShowIntersection}[2]{
\fill
[name intersections={of=#1 and #2, name=i, total=\t}]
\foreach \s in {1,...,\t}{(i-\s)
node[circle,inner sep=0pt,minimum size=4pt,draw=black,fill=red] (intersection\s) {}};
}
\begin{document}
\begin{frame}
\frametitle{MWE}
\centering
\begin{tikzpicture}
\begin{axis}
\addplot [name path global=f] {-x};
\addplot [name path global=g] {0};
\ShowIntersection{f}{g}
\end{axis}
\end{tikzpicture}
\end{frame}
\end{document}