用条形表示的间隔

用条形表示的间隔

是否可以在 Latex 中重现两端带有垂直条的封闭间隔的上划线?请参见下图。

在此处输入图片描述

答案1

这是一组可以执行的宏。该宏\interval具有两个字母的可选参数;如果省略,则暗示打开。仅指定o或与和分别c相同。oocc

\documentclass{article}
\usepackage{amsmath}
\usepackage{stmaryrd}

\makeatletter
\newcommand{\interval}[2][oo]{%
  \mathord{\vbox{\offinterlineskip\m@th
    \ialign{##\cr
      \csname @interval#1\endcsname\cr
      $#2$\cr
    }%
  }}%
}

\newcommand{\leaderbar}{%
  \mkern-7mu
  \cleaders\hbox{$\scriptscriptstyle\mkern-2mu{\relbar}\mkern-2mu$}\hfill
  \mkern-7mu
}
\newcommand{\@intervaloo}{%
  $\scriptscriptstyle{\relbar}\leaderbar{\relbar}$%
}
\newcommand{\@intervalco}{%
  $\scriptscriptstyle{\mapstochar\relbar}\leaderbar{\relbar}$%
}
\newcommand{\@intervaloc}{%
  $\scriptscriptstyle{\relbar}\leaderbar{\relbar\mkern-1mu\mapsfromchar}$%
}
\newcommand{\@intervalcc}{%
  $\scriptscriptstyle{\mapstochar\relbar}\leaderbar{\relbar\mkern-1mu\mapsfromchar}$%
}
\let\@intervalc\@intervalcc
\let\@intervalo\@intervaloo
\makeatother

\begin{document}

\emph{Intervals} are denoted by bars: $\interval{a,b}$ is an open,
$\interval[cc]{a,b}$ is a closed interval; half-open intervals are
denoted by $\interval[oc]{a,b}$ and $\interval[co]{a,b}$.

\medskip

\noindent
\begin{tabular}{@{}ll@{}}
\verb|\interval{a,b}| & $\interval{a,b}$ \\
\verb|\interval[o]{a,b}| & $\interval[o]{a,b}$ \\
\verb|\interval[oo]{a,b}| & $\interval[oo]{a,b}$ \\
\verb|\interval[c]{a,b}| & $\interval[c]{a,b}$ \\
\verb|\interval[cc]{a,b}| & $\interval[cc]{a,b}$ \\
\verb|\interval[oc]{a,b}| & $\interval[oc]{a,b}$ \\
\verb|\interval[co]{a,b}| & $\interval[co]{a,b}$
\end{tabular}

\end{document}

在此处输入图片描述

相关内容