如何使用 xlop 包包含美元或英镑符号?

如何使用 xlop 包包含美元或英镑符号?

我希望乘法中的第一个数字包含美元符号或英镑符号。例如,问题是 $12.34 x 56。在某些情况下,我希望数字末尾有 $ 符号,例如 12,34$

\documentclass[twoside,12pt]{article}
\usepackage[hmargin=0.75in,vmargin=0.5in,includeheadfoot,headheight=10mm,headsep=4mm]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{fancyhdr}
\usepackage{xcolor}
\usepackage{xlop}
\newcommand\gobble[1]{}
\pagestyle{fancy}
\fancyhf{}
\renewcommand{\headrulewidth}{0.0pt}
\begin{document}
\fontsize{14pt}{24pt}
\begin{minipage}[t][4.2cm][t]{0.5\textwidth} \textcolor{gray}{1. }
\opmul[voperation=top,voperator=bottom]{12.34}{56} \quad
\opmul[voperation=top,voperator=bottom,resultstyle=gobble,displayintermediary=None]{12.34}{56}
\end{minipage}
\clearpage
\end{document}

答案1

我将附加组件与 xlop 宏本身分开进行。我引入了一个设置宏\opsignsetup{<symbol>}{<l or r positioning>}(默认为左侧定位)。然后,使用 的标准参数格式\$来使用它。\signopmul[]{}{}\opmul

该答案目前是硬连线的,以便voperation=top,voperator=bottom选择选项。

\documentclass[landscape,twoside,12pt]{article}
\usepackage[hmargin=0.75in,vmargin=0.5in,includeheadfoot,headheight=10mm,headsep=4mm]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{fancyhdr}
\usepackage{xcolor}
\usepackage{xlop}
\usepackage{stackengine}
\newcommand\gobble[1]{}
\pagestyle{fancy}
\fancyhf{}
\renewcommand{\headrulewidth}{0.0pt}
\newcommand\opsign{\$}
\newcommand\opsignpos{l}
\newcommand\opsignsetup[2]{\def\opsign{#1}\def\opsignpos{#2}}
\newcommand\signopmul[3][\relax]{%
  \def\tmparg{}%
  \ifx\relax#1\else\def\tmparg{#1,}\fi%
  \savestack\tmp{\expandafter\opmul\expandafter[\tmparg %
    voperation=top,voperator=bottom]{#2}{#3}}%
  \def\stacktype{L}%
  \if l\opsignpos%
  {\belowbaseline[0pt]{%
    \stackunder[\dimexpr\dp\tmpcontent-.4\ht\strutbox\relax]{%
    \small\opsign}{\small\opsign}}%
  }%
  \belowbaseline[0pt]{\tmp}%
  \else\if r\opsignpos
  \belowbaseline[0pt]{\tmp}%
  {\belowbaseline[0pt]{%
    \stackunder[\dimexpr\dp\tmpcontent-.4\ht\strutbox\relax]{%
    \small\opsign}{\small\opsign}}%
  }%
  \fi\fi
}
\begin{document}
\fontsize{14pt}{24pt}
\begin{minipage}[t][4.2cm][t]{0.5\textwidth} \textcolor{gray}{1. }
\opmul[voperation=top,voperator=bottom]{12.34}{56} \quad
\opmul[voperation=top,voperator=bottom,resultstyle=\gobble,displayintermediary=None]{12.34}{56}
\end{minipage}

\begin{minipage}[t][4.2cm][t]{0.5\textwidth} \textcolor{gray}{2. }
\signopmul{12.34}{56} \quad
\signopmul[resultstyle=\gobble,displayintermediary=None]{12.34}{56}
\end{minipage}

\opsignsetup{\pounds}{r}
\begin{minipage}[t][4.2cm][t]{0.5\textwidth} \textcolor{gray}{3. }
\signopmul{12.34}{56} \quad
\signopmul[resultstyle=\gobble,displayintermediary=None]{12.34}{56}
\end{minipage}

\end{document}

在此处输入图片描述

对于问题的底部对齐版本,这里是替代方案(具有相同的调用语法)

\documentclass[landscape,twoside,12pt]{article}
\usepackage[hmargin=0.75in,vmargin=0.5in,includeheadfoot,headheight=10mm,headsep=4mm]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{fancyhdr}
\usepackage{xcolor}
\usepackage{xlop}
\usepackage{stackengine}
\newcommand\gobble[1]{}
\pagestyle{fancy}
\fancyhf{}
\renewcommand{\headrulewidth}{0.0pt}
\newcommand\opsign{\$}
\newcommand\opsignpos{l}
\newcommand\opsignsetup[2]{\def\opsign{#1}\def\opsignpos{#2}}
\newcommand\signopmul[3][\relax]{%
  \def\tmparg{}%
  \ifx\relax#1\else\def\tmparg{#1,}\fi%
  \savestack\tmp{\expandafter\opmul\expandafter[\tmparg %
    voperation=bottom,voperator=bottom]{#2}{#3}}%
  \def\stacktype{L}%
  \if l\opsignpos%
  {\abovebaseline[0pt]{%
    \stackon[\dimexpr\dp\tmpcontent+\ht\tmpcontent-1.4\ht\strutbox\relax]{%
    \small\opsign}{\small\opsign}}%
  }%
  \abovebaseline[0pt]{\tmp}%
  \else\if r\opsignpos
  \abovebaseline[0pt]{\tmp}%
  {\abovebaseline[0pt]{%
    \stackon[\dimexpr\dp\tmpcontent+\ht\tmpcontent-1.4\ht\strutbox\relax]{%
    \small\opsign}{\small\opsign}}%
  }%
  \fi\fi
}
\begin{document}
\fontsize{14pt}{24pt}
\begin{minipage}[t][4.2cm][t]{0.5\textwidth} \textcolor{gray}{1. }
\opmul[voperation=top,voperator=bottom]{12.34}{56} \quad
\opmul[voperation=top,voperator=bottom,resultstyle=\gobble,displayintermediary=None]{12.34}{56}
\end{minipage}

\begin{minipage}[t][4.2cm][t]{0.5\textwidth} \textcolor{gray}{2. }
\signopmul{12.34}{56} \quad
\signopmul[resultstyle=\gobble,displayintermediary=None]{12.34}{56}
\end{minipage}

\opsignsetup{\pounds}{r}
\begin{minipage}[t][4.2cm][t]{0.5\textwidth} \textcolor{gray}{3. }
\signopmul{12.34}{56} \quad
\signopmul[resultstyle=\gobble,displayintermediary=None]{12.34}{56}
\end{minipage}

\end{document}

相关内容