如何创建以下符号?分数函数

如何创建以下符号?分数函数

如何创建以下符号? 在此处输入图片描述

答案1

最简单的方法是使用两条规则,并用斜线将它们连接起来,斜线由一点负空间构成。这确实不是与内容进行缩放,需要采用更复杂的方法,例如将东西放入盒子中并测量高度。

\documentclass{article}
\usepackage{amsmath}
\newcommand\fractional[2]{%
  \underline{#1}\mkern-2mu\raise .1ex \hbox{$\big/$}\mkern-1.5mu\overline{#2}
}
\begin{document}
\[ \varPhi^{n,n}(x) = f_0 + \fractional{x-x_0}{\rho(x_0,x_1)} \]
\end{document}

在此处输入图片描述


这是一个可以很好地扩展的变体。

\documentclass{article}
\usepackage{amsmath}
\newcommand\fractional[2]{%
  \mathpalette\dofractional{{#1}{#2}}
}
\newcommand\dofractional[2]{%
  \dofractionalindeed#1#2
}
\newcommand\dofractionalindeed[3]{%
  \setbox0=\hbox{$#1#2$}%
  \setbox1=\hbox{$#1#3$}%
  \ifdim\ht0>\ht1
    \dimen0=\dimexpr\ht0+1pt
  \else
    \dimen0=\dimexpr\ht1+1pt
  \fi
  \ifdim\dp0>\dp1
    \dimen1=\dimexpr\dp0+1pt
  \else
    \dimen1=\dimexpr\dp1+1pt
  \fi
  \rlap{\vrule height -\dimen1 width \wd0 depth \dimexpr\dimen1+\fontdimen8\textfont3}
  \box0
  \mkern-2mu
  \mathord{\left/\vrule height \dimen0 depth \dimen1 width 0pt\right.\kern-\nulldelimiterspace}
  \mkern-2mu
  \rlap{\vrule height \dimexpr\dimen0+\fontdimen8\textfont3 width \wd1 depth -\dimen0}
  \box1
}
\begin{document}
\[ \varPhi^{n,n}(x) = f_0 + \scriptscriptstyle \fractional{x-x_0}{\rho(x_0,x_1)} \]
\[ \varPhi^{n,n}(x) = f_0 + \scriptstyle \fractional{x-x_0}{\rho(x_0,x_1)} \]
\[ \varPhi^{n,n}(x) = f_0 + \fractional{x-x_0}{\rho(x_0,x_1)} \]
\[ \varPhi^{n,n}(x) = f_0 + \textstyle \fractional{\int x-x_0}{\sum \rho(x_0,x_1)} \]
\[ \varPhi^{n,n}(x) = f_0 + \fractional{\int x-x_0}{\sum \rho(x_0,x_1)} \]
\end{document}

在此处输入图片描述

答案2

以下解决方案绘制了包含所有三个部分的完整线绘图操作。优点是

  • 正确的线路连接,
  • 恒定的线宽。

绘图是用 TikZ 完成的(它还允许更改线条样式、线条连接和线帽)。

  • 从字体尺寸寄存器中提取正确的线宽:

    \fontdimen8\<text|script|scriptscript>font3
    
  • \underline在和中,公式与线条之间有三个线宽的间隙\overline。此外,TeXs 还设置了线条下方/上方的外边距,其量为一个线宽。

  • \overline使用狭窄公式的数学样式。例如,上标会稍微降低一点。LuaTeX 有命令可以设置狭窄的数学样式。如果没有 LuaTeX,解决方案将使用\cramped包的宏mathtools

通过示例和测试用例实现:

\documentclass{article}

\usepackage{ifluatex}
\ifluatex
  \IfFileExists{luatex85.sty}{\usepackage{luatex85}}{}
  % LuaTeX provides \<mathstyle>cramped
\fi
\begingroup\expandafter\expandafter\expandafter\endgroup
\expandafter\ifx\csname crampedscriptstyle\endcsname\relax
  \usepackage{mathtools} % for \cramped
  \newcommand*{\SetCrampedStyle}[2]{%
    \cramped[#1]{#2}%
  }
\else
  \newcommand*{\SetCrampedStyle}[2]{%
    {%
      \ifx#1\displaystyle\crampeddisplaystyle
      \else\ifx#1\textstyle\crampedtextstyle
      \else\ifx#1\scriptstyle\crampedscriptstyle
      \else\crampedscriptscriptstyle
      \fi\fi\fi
      #2%
    }%
  }
\fi
\usepackage{tikz}

\makeatletter
\newcommand*{\fractional}[2]{%
  \mathpalette{\@fractional{#1}{#2}}{}%
}
\newcommand*{\fractionalAngle}{65}
\newcommand*{\@fractional}[4]{%
  % #1, #2: arguments of \fractional
  % #3: math style
  % #4: unused
  %
  % Get the line width for this math style
  \edef\@LineWidth{%
    \the\fontdimen8
    \ifx#3\displaystyle\textfont
    \else\ifx#3\textstyle\textfont
    \else\ifx#3\scriptstyle\scriptfont
    \else\scriptscriptfont
    \fi\fi\fi
    3%
  }
  %
  % Set the left and right part in boxes for measurment and usage.
  % Note the cramped style for the right part as in \overline and \sqrt.
  \sbox0{$#3#1\m@th$}%
  \sbox2{$#3\SetCrampedStyle{#3}{#2}\m@th$}%
  %
  % Calculate the total height for the slanted line
  \edef\@SlashTotalHeight{%
    \the\dimexpr
      \dp0 + \ht2
      + \@LineWidth * 7 % 2 * (3 [space] + 1/2 [line])
    \relax
  }%
  %
  % Calculate the width of the slanted line
  \pgfmathsetlengthmacro\@SlashWidth{%
    \@SlashTotalHeight * cos(\fractionalAngle)%
  }%
  %
  \begin{tikzpicture}[
    inner sep=0pt,
    outer sep=0pt,
    baseline=(Left.base),
    line width=\@LineWidth,
  ]
    \draw[overlay] % Bounding box is set later
      % Left and right part are set as nodes
      node[anchor=base east] (Left) {\copy0}
      ++(\@SlashWidth, 0)
      node[anchor=base west] (Right) {\copy2}
      %
      % Line is drawn
      (Left.south west)
      ++(0, -3.5\pgflinewidth)
      -- ++(\wd0, 0)
      -- ++(\@SlashWidth, \@SlashTotalHeight)
      -- ++(\wd2, 0)
    ;%
    % Bounding box
    \useasboundingbox[outer sep=-.5\pgflinewidth]
      (Left.south west) ++(0, -5\pgflinewidth)
      (Right.north east) ++(0, 5\pgflinewidth)
    ;%
  \end{tikzpicture}%
}
\makeatother


% Testing
\usepackage{amsmath}
\usepackage{color}
\newcommand*{\Annot}[1]{\text{\scriptsize\quad(#1)}}

\begin{document}
\[ \varPhi^{n,n}(x) = f_0 + \fractional{x-x_0}{\rho(x_0,x_1)} \]
\[
  \underline{x_0}
  \begingroup\color{red}
    \fractional{\color{black}x_0}{\color{black}x^{\color{red}0}}
  \endgroup
  \overline{x^{\color{red}0}}
  \Annot{Positions}
\]
\[
  \def\test{
    {\color{blue}\fractional{\color{black}x_0}{\color{black}x^0}}
  }
  \test\,
  \scriptstyle\test\,
  \scriptscriptstyle\test
  \Annot{Line widths}
\]
\[
  \setlength{\fboxsep}{0pt}
  \setlength{\fboxrule}{.2pt}
  \def\test#1{\textcolor{red}{\fbox{\color{black}$#1$}}}%
  \test{\underline{x_0}}\,
  \test{\fractional{x_0}{x^0}}\,
  \test{\overline{x^0}}
  \Annot{Bounding boxes}
\]
\end{document}

结果

相关内容