创建三面盒子,以“封闭”地板和天花板功能

创建三面盒子,以“封闭”地板和天花板功能

喜欢卡梅隆·马丁谁问这个问题,我想要一个运算符的符号,用严格不等式 代替\floor和中的弱不等式。\ceil乔丹·格伦提出了\ceil{\bar{N^\ast}}等,这是一个很好的解决方案,但从排版上看并不美观。我认为构造 3 面框会更美观,例如\strictFloorstrictCeil,它们将封闭N^\ast在框中,分别省略框的底部和顶部。使用\xoverline定义的命令这里,(以及类似地\xunderline沿着同样的思路的命令),我构造了

\def\strictCeil#1{\left|\xoverline[1.1]{#1}\right|}

但是之后

$\strictCeil{N^\ast}$

不幸的是,这是一个非常丑陋的三面盒子的尝试:

在此处输入图片描述

因为边缘不对齐,字体不匹配。但是我已经达到了乳胶容量的极限。有人能建议如何获得一个漂亮的版本,让线条都具有相同的风格,并且相互接触吗?

答案1

只是为了倡导过去的优良方法:

% My standard header for TeX.SX answers:
\documentclass[a4paper]{article} % To avoid confusion, let us explicitly 
                                 % declare the paper format.

\usepackage[T1]{fontenc}         % Not always necessary, but recommended.
% End of standard header.  What follows pertains to the problem at hand.

\usepackage{amsmath} % by default... :-)

\makeatletter

\newcommand*\strictceil[1]{%
    % "\mathord" is required to get an atom that can carry
    % sub-/superscripts:
    \mathord{\mathpalette\@strictceil{#1}}%
}
\newcommand*\@strictceil[2]{%
    \vbox{\m@th
        % Save <default-rule-thickness> in "\dimen@":
        \dimen@ \fontdimen 8
            \ifx\scriptscriptstyle #1%
                \scriptscriptfont
            \else\ifx\scriptstyle #1%
                \scriptfont
            \else
                \textfont
            \fi\fi \thr@@
        \kern \dimen@ % see Appendix G, Rule 9
        \hbox{%
            \vrule \@width\dimen@
            \vbox{%
                \kern -\dimen@
                \hbox{$#1\overline{%
                    \kern \thr@@\dimen@
                    \begingroup
                        #2% possible changes to "\dimen@" are kept local
                    \endgroup
                    \kern \thr@@\dimen@
                }$}%
            }%
            \vrule \@width\dimen@
        }%
    }%
}

\makeatother



\begin{document}

Let's try $\strictceil{N^{\ast}}$, and \( \strictceil{a}+\strictceil{b} = 
\strictceil{f(x)}+\strictceil{g(y)} \).

Now in display:
\begin{align*}
    x_{\strictceil{t}_{1+\strictceil{q}}} &= \frac{
            \strictceil{a}+\frac{\strictceil{m}}{\strictceil{n}}
        }{
            \strictceil{c}+\frac{\strictceil{r}}{\strictceil{s}}
        }
    \\ % compare sizes with:
    x_{t_{1+q}} &= \frac{
            a+\frac{m}{n}
        }{
            c+\frac{r}{s}
        }
\end{align*}

\end{document}

输出:

代码输出

答案2

从您的帖子中无法看出您使用的是纯 TeX、LaTeX 还是其他格式。我假设是 LaTeX,但该解决方案也可以适用于其他格式。

解决方案 1:tikz

\usepackage{tikz}
\newcommand\strictCeil[1]%
  {\begin{tikzpicture}[baseline=(A.base)]
   \node[inner sep=1pt] (A) {$#1$};
   \draw (A.south west) --
         (A.north west) --
         (A.north east) --
         (A.south east);
   \end{tikzpicture}%
  }

绘制命令非常直观,可以轻松适应顶部打开的框。tikz为了一个额外的符号而引入机器可能有点过头了。

解决方案 2:负间距

\newcommand\strictCeil[1]{\left|\!\xoverline[1.1]{#1}\!\right|}

在此处输入图片描述

\documentclass{article}
% Solution 1: Tikz
\usepackage{tikz}
\newcommand\strictCeilA[1]%
  {\begin{tikzpicture}[baseline=(A.base)]
   \node[inner sep=1pt] (A) {$#1$};
   \draw (A.south west) --
         (A.north west) --
         (A.north east) --
         (A.south east);
   \end{tikzpicture}%
  }

% Solution 2: negative spacing
\makeatletter
\newsavebox\myboxA
\newsavebox\myboxB
\newlength\mylenA
\newcommand*\xoverline[2][0.75]{%
    \sbox{\myboxA}{$\m@th#2$}%
    \setbox\myboxB\null% Phantom box
    \ht\myboxB=\ht\myboxA%
    \dp\myboxB=\dp\myboxA%
    \wd\myboxB=#1\wd\myboxA% Scale phantom
    \sbox\myboxB{$\m@th\overline{\copy\myboxB}$}%  Overlined phantom
    \setlength\mylenA{\the\wd\myboxA}%   calc width diff
    \addtolength\mylenA{-\the\wd\myboxB}%
    \ifdim\wd\myboxB<\wd\myboxA%
       \rlap{\hskip 0.5\mylenA\usebox\myboxB}{\usebox\myboxA}%
    \else
        \hskip -0.5\mylenA\rlap{\usebox\myboxA}{\hskip 0.5\mylenA\usebox\myboxB}%
    \fi}
\makeatother
\newcommand\strictCeilB[1]{\left|\!\xoverline[1.1]{#1}\!\right|}

\begin{document}
Using TikZ: Some text $\strictCeilA{N^\ast}$ some text.

Using negative space/kerning: Some text $\strictCeilB{N^\ast}$ some text.

\end{document}

相关内容