tikzpicture 轴上的右括号标记用于绘制封闭集

tikzpicture 轴上的右括号标记用于绘制封闭集

我正在尝试绘制一个简单的集合区间,其中左/右括号表示开集,左/右括号表示闭集。以下是我绘制它的方式:

\begin{adjustbox}{width=\textwidth}
\begin{tikzpicture}
\begin{axis}[
  axis y line=none, axis lines=left, axis line style={-},
  xmin=-1, xmax=11, ymin=0, ymax=1, xlabel=$\mathbb{R}$, restrict y to domain=0:1, xtick={0,...,10}, extra x ticks = {0}, point meta=explicit symbolic, axis lines = middle,
  scatter/classes={open={mark=*,draw=magenta,fill=white},closed={mark=*,red}, closedleft={mark=text,text mark=[,color=black},closedright={mark=text,text mark=],color=black},openleft={mark=text,text mark=(,color=black},openright={mark=text,text mark=),color=black}, point={mark=*,red}},
  %axis line style={latex-latex}
]
\addplot[scatter,blue,ultra thick] table [y expr=0,meta index=1, header=false] {
    0 closedleft
    4 closedright
};
\node[coordinate,label=above:{$A$}] at (axis cs:-0.5,0.02) {};
\end{axis}
\end{tikzpicture}
\end{adjustbox}

看起来是这样的:

尝试闭集

closedright您可以看到问题,右括号缺失,但左括号显示正常。当我将标记更改为带有右括号的单词时,可以看到发生了什么提示:

\begin{adjustbox}{width=\textwidth}
\begin{tikzpicture}
\begin{axis}[
  axis y line=none, axis lines=left, axis line style={-},
  xmin=-1, xmax=11, ymin=0, ymax=1, xlabel=$\mathbb{R}$, restrict y to domain=0:1, xtick={0,...,10}, extra x ticks = {0}, point meta=explicit symbolic, axis lines = middle,
  scatter/classes={open={mark=*,draw=magenta,fill=white},closed={mark=*,red}, closedleft={mark=text,text mark=[,color=black},closedright={mark=text,text mark=wo]rd,color=black},openleft={mark=text,text mark=(,color=black},openright={mark=text,text mark=),color=black}, point={mark=*,red}},
  %axis line style={latex-latex}
]
\addplot[scatter,blue,ultra thick] table [y expr=0,meta index=1, header=false] {
    0 closedleft
    4 closedright
};
\node[coordinate,label=above:{$A$}] at (axis cs:-0.5,0.02) {};
\end{axis}
\end{tikzpicture}
\end{adjustbox}

问题原因提示

右括号似乎专门充当文本标记的终止符。有人知道这里发生了什么吗?

答案1

为了不使解析器混淆,将括号括起来{即可}

\documentclass{article}
\usepackage{adjustbox}
\usepackage{amsfonts}
\usepackage{geometry}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}

\begin{document}
\begin{adjustbox}{width=\textwidth}
    \begin{tikzpicture}
    \begin{axis}[
      axis y line=none, axis lines=left, axis line style={-},
      xmin=-1, xmax=11, ymin=0, ymax=1, xlabel=$\mathbb{R}$, restrict y to domain=0:1, xtick={0,...,10}, extra x ticks = {0}, point meta=explicit symbolic, axis lines = middle,
      scatter/classes={open={mark=*,draw=magenta,fill=white},closed={mark=*,red}, closedleft={mark=text,text mark={[},color=black},closedright={mark=text,text mark={]},color=black},openleft={mark=text,text mark={(},color=black},openright={mark=text,text mark={)},color=black}, point={mark=*,red}},
      %axis line style={latex-latex}
    ]
    \addplot[scatter,blue,ultra thick] table [y expr=0,meta index=1, header=false] {
        0 closedleft
        4 closedright
    };
    \node[coordinate,label=above:{$A$}] at (axis cs:-0.5,0.02) {};
    \end{axis}
    \end{tikzpicture}
\end{adjustbox}    
\end{document}

在此处输入图片描述

相关内容