逐字环境中的分数

逐字环境中的分数

首先:这是一个类似于这里

如何在绿色框中写入分数作为输出?

分数应该出现在之后,2类似于的输出\frac{3}{5}但像素化,无论是在显示的输入(绿屏,左)还是显示的输出(绿屏,右)。

可取但不必要:分子高度应为 5 像素,然后是 1 像素空白,然后是 1 水平线作为描边,然后是 1 像素空白,然后分母高度应为 5 像素。此外,分数应相对于分数前面的数字垂直居中。

输出

\documentclass[
  a4paper,
  11pt
]{article}

\usepackage[varg]{newpxmath}
\usepackage[
  hmargin = 2.4cm,
  vmargin = 3cm
]{geometry}

\usepackage[most]{tcolorbox}
  \colorlet{blackened}{black!90!white}
  \colorlet{blackish}{black!70!white}
  \colorlet{greyish}{black!60!white}
  \colorlet{lightgreyish}{black!10!white}
  \colorlet{whiteish}{white}
  \colorlet{orangeish}{yellow!90!red}
  \colorlet{greenish}{green!16!gray}
  \colorlet{redish}{red!80!black}

\tcbset{
  calbackground/.style = {
    enhanced,
    leftright skip = 0.15cm,
    beforeafter skip = 0pt,
    toptitle = 0mm,
    bottomtitle = 0mm,
    right = 3pt,
    left = 3pt,
    top = 3pt,
    bottom = 3pt,
    boxsep = 0pt,
    boxrule = 0mm,
    sharp corners,
    sidebyside,
    sidebyside gap = 6pt,
    lefthand ratio = 0.622,
    bicolor,
    colback = lightgreyish,
    colbacklower = greenish,
    colframe = white,
    autoparskip,
  }
}

\newtcbtheorem[no counter]{calx}{Calculator}{calbackground}{cax}

\newtcbox{\KY}[1][]{
  enhanced,
  on line,
  arc = 2pt,
  outer arc = 2pt,
  boxrule = 0pt,
  bottomrule = 0.15mm,
  rightrule = 0.2mm,
  boxsep = 0pt,
  left = 0pt,
  right = 0pt,
  top = 1pt,
  bottom = 1pt,
  interior style = {
    top color = blackish,
    bottom color = blackened
  },
  colframe = greyish,
  width = 2.5em,
  tcbox width = forced center,
  equal height group = K,
  valign = center,
  fontupper = \footnotesize\sffamily,
  coltext = orangeish,
  before upper = \vrule width 0pt height 2ex depth 1ex\relax,
}

\newtcbox{\KYm}[1][]{
    enhanced,
    on line,
    arc = 2pt,
    outer arc = 2pt,
    boxrule = 0pt,
    bottomrule = 0.25mm,
    rightrule = 0.2mm,
    boxsep = 0pt,
    left = 0pt,
    right = 0 pt,
    top = 1pt,
    bottom = 1pt,
    interior style = {
      top color = blackish,
      bottom color = blackened
    },
    colframe = greyish,
    width = 2.5em,
    tcbox width = forced center,
    equal height group = K,
    valign = center,
    fontupper = \footnotesize\sffamily,
    coltext = orangeish,
    before upper = \vrule width 0pt height 2ex depth 1ex\relax$,
    after upper = $,
    }

\newtcbox{\KN}{
  enhanced,
  on line,
  arc = 2pt, outer arc = 2pt,
  boxrule = 0pt,
  bottomrule = 0.15mm,
  rightrule = 0.2mm,
  boxsep = 0pt,
  left = 0pt,
  right = 0pt,
  top = 1pt,
  bottom = 1pt,
  interior style = {
    top color = blackish,
    bottom color = blackened
  },
  colframe = greyish,
  width = 2.5em,
  tcbox width = forced center,
  equal height group = K,
  valign = center,
  fontupper = \footnotesize\sffamily,
  coltext = whiteish,
  before upper = \vrule width 0pt height 2ex depth 1ex\relax,
}

\usepackage{lcd}
  \LCDcolors{black}{greenish}
  \DefineLCDchar{sq}{11100001000100011100000000000000000}
  \DefineLCDchar{tm}{00000100010101000100010101000100000}
  \DefineLCDchar{dv}{00000001000000011111000000010000000}
  \DefineLCDchar{mu}{00011000011110100001000000000000000}
  \DefineLCDchar{sc}{11011010011001000000000000000000000}

\DeclareMathOperator{\ee}{\textrm{e}}

\usepackage{MnSymbol}
\usepackage{xfrac}

\begin{document}

\begin{calx}{}{}
  \KY{2nd}
  \KYm{\frac{\mathrm{n}}{\mathrm{d}}}
  \KN{2}
  \KYm{\smalltriangleright}
  \KN{3}
  \KYm{\smalltriangleright}
  \KN{5}
  \KYm{\smalltriangleright}
  \KY{enter}
  \tcblower
  {\Large
   \vspace*{-0.5ex}
   \textLCD[0]{19}|2|
   \textLCD[0]{18}|                 2|}
\end{calx}

\end{document}

答案1

不确定我是否真的理解\textLCD宏的工作方式,但使用一种非常手动的方法(还有什么)堆叠,我能够(希望)做一些类似于期望的事情。

修订的解决方案

我最初有\pixelfrac{NUMERATOR}{DENOMINATOR}可以创建分数的,但我仍然必须使用堆栈将其覆盖在该行的其他内容上。现在,我发现我能够将宏(无参数)内联插入到中\textLCD。但是,要使用此功能,我必须\pixelfrac在之前调用(带参数)\textLCD并让它将的内容保存\pixelfrac到没有参数的宏中。然后我可以在的参数中使用该无参数宏\textLCD

然后我发现我需要使用零宽度,\pixelfrac这对 的水平间距有影响\textLCD。因此,我必须以以下\pixelfrac形式添加一个额外的参数

\pixelfrac{NUMERATOR}{DENOMINATOR}{EVENTUAL COLUMN PLACEMENT}

这样\pixelfrac就可以在盒子中填充适当的空间,使其出现在所需的位置。

因此,在下面的 MWE 中,像素化构造的核心是:

   \pixelfrac{3}{5}{2}%
   \pixelfrac[\thefracB]{1}{5}{18}%
   \textLCD[0]{18}|2\thefrac*|
   \textLCD[0]{18}|                5\thefracB|}

这表示默认宏\thefrac应将分数 3/5 放入第 2 列,\thefracB将 1/5 放入第 18 列。

妇女权利委员会:

\documentclass[
  a4paper,
  11pt
]{article}

\usepackage[varg]{newpxmath}
\usepackage[
  hmargin = 2.4cm,
  vmargin = 3cm
]{geometry}

\usepackage[most]{tcolorbox}
  \colorlet{blackened}{black!90!white}
  \colorlet{blackish}{black!70!white}
  \colorlet{greyish}{black!60!white}
  \colorlet{lightgreyish}{black!10!white}
  \colorlet{whiteish}{white}
  \colorlet{orangeish}{yellow!90!red}
  \colorlet{greenish}{green!16!gray}
  \colorlet{redish}{red!80!black}

\tcbset{
  calbackground/.style = {
    enhanced,
    leftright skip = 0.15cm,
    beforeafter skip = 0pt,
    toptitle = 0mm,
    bottomtitle = 0mm,
    right = 3pt,
    left = 3pt,
    top = 3pt,
    bottom = 3pt,
    boxsep = 0pt,
    boxrule = 0mm,
    sharp corners,
    sidebyside,
    sidebyside gap = 6pt,
    lefthand ratio = 0.622,
    bicolor,
    colback = lightgreyish,
    colbacklower = greenish,
    colframe = white,
    autoparskip,
  }
}

\newtcbtheorem[no counter]{calx}{Calculator}{calbackground}{cax}

\newtcbox{\KY}[1][]{
  enhanced,
  on line,
  arc = 2pt,
  outer arc = 2pt,
  boxrule = 0pt,
  bottomrule = 0.15mm,
  rightrule = 0.2mm,
  boxsep = 0pt,
  left = 0pt,
  right = 0pt,
  top = 1pt,
  bottom = 1pt,
  interior style = {
    top color = blackish,
    bottom color = blackened
  },
  colframe = greyish,
  width = 2.5em,
  tcbox width = forced center,
  equal height group = K,
  valign = center,
  fontupper = \footnotesize\sffamily,
  coltext = orangeish,
  before upper = \vrule width 0pt height 2ex depth 1ex\relax,
}

\newtcbox{\KYm}[1][]{
    enhanced,
    on line,
    arc = 2pt,
    outer arc = 2pt,
    boxrule = 0pt,
    bottomrule = 0.25mm,
    rightrule = 0.2mm,
    boxsep = 0pt,
    left = 0pt,
    right = 0 pt,
    top = 1pt,
    bottom = 1pt,
    interior style = {
      top color = blackish,
      bottom color = blackened
    },
    colframe = greyish,
    width = 2.5em,
    tcbox width = forced center,
    equal height group = K,
    valign = center,
    fontupper = \footnotesize\sffamily,
    coltext = orangeish,
    before upper = \vrule width 0pt height 2ex depth 1ex\relax$,
    after upper = $,
    }

\newtcbox{\KN}{
  enhanced,
  on line,
  arc = 2pt, outer arc = 2pt,
  boxrule = 0pt,
  bottomrule = 0.15mm,
  rightrule = 0.2mm,
  boxsep = 0pt,
  left = 0pt,
  right = 0pt,
  top = 1pt,
  bottom = 1pt,
  interior style = {
    top color = blackish,
    bottom color = blackened
  },
  colframe = greyish,
  width = 2.5em,
  tcbox width = forced center,
  equal height group = K,
  valign = center,
  fontupper = \footnotesize\sffamily,
  coltext = whiteish,
  before upper = \vrule width 0pt height 2ex depth 1ex\relax,
}

\usepackage{lcd}
  \LCDcolors{black}{greenish}
  \DefineLCDchar{sq}{11100001000100011100000000000000000}
  \DefineLCDchar{tm}{00000100010101000100010101000100000}
  \DefineLCDchar{dv}{00000001000000011111000000010000000}
  \DefineLCDchar{mu}{00011000011110100001000000000000000}
  \DefineLCDchar{sc}{11011010011001000000000000000000000}

\DeclareMathOperator{\ee}{\textrm{e}}

\newlength\cwidth
\Large\cwidth=.61em\relax\normalsize
\newlength\coffset
\Large\coffset=.3em\relax\normalsize

\usepackage{MnSymbol}
\usepackage{xfrac}
\usepackage{stackengine}
% \pixelfrac{NUMERATOR}{DENOMINATOR}{EVENTUAL COLUMN PLACEMENT}
\newcommand\pixelfrac[4][\thefrac]{%
  \setbox0=\hbox{\tiny\textLCD[0]{0}|#2|}%
  \setbox2=\hbox{\tiny\textLCD[0]{0}|-|}%
  \setbox4=\hbox{\tiny\textLCD[0]{0}|#3|}%
% \scriptsize GETS CLIPPED...MUST USE \tiny
%  \setbox0=\hbox{\scriptsize\textLCD[0]{0}|#2|}%
%  \setbox2=\hbox{\scriptsize\textLCD[0]{0}|-|}%
%  \setbox4=\hbox{\scriptsize\textLCD[0]{0}|#3|}%
  \savestack#1{\kern-\coffset\kern#4\cwidth\smash{\raisebox{6pt}{\stackunder[-9pt]{\copy2}{\stackon[2pt]{\copy4}{\copy0}}}}\kern-#4\cwidth\kern\coffset}%
}
\begin{document}

\begin{calx}{}{}
  \KY{2nd}
  \KYm{\frac{\mathrm{n}}{\mathrm{d}}}
  \KN{2}
  \KYm{\smalltriangleright}
  \KN{3}
  \KYm{\smalltriangleright}
  \KN{5}
  \KYm{\smalltriangleright}
  \KY{enter}
  \tcblower
  {\Large
   \vspace*{-0.5ex} 
   \pixelfrac{3}{5}{2}%
   \pixelfrac[\thefracB]{1}{5}{18}%
   \textLCD[0]{18}|2\thefrac*|
   \textLCD[0]{18}|                5\thefracB|}
\end{calx}

\end{document}

在此处输入图片描述

原始代码

\documentclass[
  a4paper,
  11pt
]{article}

\usepackage[varg]{newpxmath}
\usepackage[
  hmargin = 2.4cm,
  vmargin = 3cm
]{geometry}

\usepackage[most]{tcolorbox}
  \colorlet{blackened}{black!90!white}
  \colorlet{blackish}{black!70!white}
  \colorlet{greyish}{black!60!white}
  \colorlet{lightgreyish}{black!10!white}
  \colorlet{whiteish}{white}
  \colorlet{orangeish}{yellow!90!red}
  \colorlet{greenish}{green!16!gray}
  \colorlet{redish}{red!80!black}

\tcbset{
  calbackground/.style = {
    enhanced,
    leftright skip = 0.15cm,
    beforeafter skip = 0pt,
    toptitle = 0mm,
    bottomtitle = 0mm,
    right = 3pt,
    left = 3pt,
    top = 3pt,
    bottom = 3pt,
    boxsep = 0pt,
    boxrule = 0mm,
    sharp corners,
    sidebyside,
    sidebyside gap = 6pt,
    lefthand ratio = 0.622,
    bicolor,
    colback = lightgreyish,
    colbacklower = greenish,
    colframe = white,
    autoparskip,
  }
}

\newtcbtheorem[no counter]{calx}{Calculator}{calbackground}{cax}

\newtcbox{\KY}[1][]{
  enhanced,
  on line,
  arc = 2pt,
  outer arc = 2pt,
  boxrule = 0pt,
  bottomrule = 0.15mm,
  rightrule = 0.2mm,
  boxsep = 0pt,
  left = 0pt,
  right = 0pt,
  top = 1pt,
  bottom = 1pt,
  interior style = {
    top color = blackish,
    bottom color = blackened
  },
  colframe = greyish,
  width = 2.5em,
  tcbox width = forced center,
  equal height group = K,
  valign = center,
  fontupper = \footnotesize\sffamily,
  coltext = orangeish,
  before upper = \vrule width 0pt height 2ex depth 1ex\relax,
}

\newtcbox{\KYm}[1][]{
    enhanced,
    on line,
    arc = 2pt,
    outer arc = 2pt,
    boxrule = 0pt,
    bottomrule = 0.25mm,
    rightrule = 0.2mm,
    boxsep = 0pt,
    left = 0pt,
    right = 0 pt,
    top = 1pt,
    bottom = 1pt,
    interior style = {
      top color = blackish,
      bottom color = blackened
    },
    colframe = greyish,
    width = 2.5em,
    tcbox width = forced center,
    equal height group = K,
    valign = center,
    fontupper = \footnotesize\sffamily,
    coltext = orangeish,
    before upper = \vrule width 0pt height 2ex depth 1ex\relax$,
    after upper = $,
    }

\newtcbox{\KN}{
  enhanced,
  on line,
  arc = 2pt, outer arc = 2pt,
  boxrule = 0pt,
  bottomrule = 0.15mm,
  rightrule = 0.2mm,
  boxsep = 0pt,
  left = 0pt,
  right = 0pt,
  top = 1pt,
  bottom = 1pt,
  interior style = {
    top color = blackish,
    bottom color = blackened
  },
  colframe = greyish,
  width = 2.5em,
  tcbox width = forced center,
  equal height group = K,
  valign = center,
  fontupper = \footnotesize\sffamily,
  coltext = whiteish,
  before upper = \vrule width 0pt height 2ex depth 1ex\relax,
}

\usepackage{lcd}
  \LCDcolors{black}{greenish}
  \DefineLCDchar{sq}{11100001000100011100000000000000000}
  \DefineLCDchar{tm}{00000100010101000100010101000100000}
  \DefineLCDchar{dv}{00000001000000011111000000010000000}
  \DefineLCDchar{mu}{00011000011110100001000000000000000}
  \DefineLCDchar{sc}{11011010011001000000000000000000000}

\DeclareMathOperator{\ee}{\textrm{e}}

\usepackage{MnSymbol}
\usepackage{xfrac}
\usepackage{stackengine}
\newcommand\pixelfrac[2]{%
  \setbox0=\hbox{\scriptsize\textLCD[0]{0}|#1|}%
  \setbox2=\hbox{\scriptsize\textLCD[0]{0}|-|}%
  \setbox4=\hbox{\scriptsize\textLCD[0]{0}|#2|}%
  \stackunder[-12pt]{\copy2}{\stackon[3pt]{\copy4}{\copy0}}%
}
\begin{document}

\begin{calx}{}{}
  \KY{2nd}
  \KYm{\frac{\mathrm{n}}{\mathrm{d}}}
  \KN{2}
  \KYm{\smalltriangleright}
  \KN{3}
  \KYm{\smalltriangleright}
  \KN{5}
  \KYm{\smalltriangleright}
  \KY{enter}
  \tcblower
  {\Large
   \vspace*{-0.5ex} 
   \setbox6=\hbox{\kern-1pt\textLCD[]{18}|2 +|}
   \stackengine{2pt}{\copy6}{\pixelfrac{3}{5}\kern9.55em}{O}{c}{F}{F}{L}
   \textLCD[0]{18}|                 2|}
\end{calx}

\end{document}

在此处输入图片描述

相关内容