答案1
这种方法可以满足您的期望
代码
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{centernot}
\usepackage{textcomp}
\usepackage{amsmath}
\newcommand{\myoverset}[2]{%
\mathop{#2}\limits^{\vbox to -.1ex{%
\kern -0.6ex\hbox{$\scriptstyle #1$}\vss}}}
\newcommand{\myunderset}[2]{%
\mathop{#2}\limits_{\vbox to -.1ex{%
\kern -1.2ex\hbox{$\scriptstyle #1$}\vss}}}
\newcommand\can[1]{\kern0.1em\centernot{#1}\kern0.1em} % Cancel command
\newcommand{\vc}[3]{\myoverset{#2}{\myunderset{#3}{\text{#1}}}} % Main environment (acc:=accent command)
\newcommand{\sq}{\text{\text\textquotesingle}} % sq:=single quote
\newcommand{\dq}{\text{\text\textquotedbl}} % dq:=double quote
\begin{document}
\begin{center}
\textbf{Normal versions}
\[
\acc{p}{\sq}{}
\acc{p}{\dq}{}
\acc{p}{}{\sq}
\acc{p}{}{\dq}
\acc{d}{\sq}{}
\acc{d}{\dq}{}
\acc{d}{}{\sq}
\acc{d}{}{\dq}
\]
\[
\acc{p}{\sq}{\sq}
\acc{p}{\dq}{\sq}
\acc{p}{\sq}{\dq}
\acc{p}{\dq}{\dq}
\acc{d}{\sq}{\sq}
\acc{d}{\dq}{\sq}
\acc{d}{\sq}{\dq}
\acc{d}{\dq}{\dq}
\]
\textbf{Cancelled versions}
\[
\can{\acc{p}{\sq}{}}
\can{\acc{p}{\dq}{}}
\can{\acc{p}{}{\sq}}
\can{\acc{p}{}{\dq}}
\can{\acc{d}{\sq}{}}
\can{\acc{d}{\dq}{}}
\can{\acc{d}{}{\sq}}
\can{\acc{d}{}{\dq}}
\]
\[
\can{\acc{p}{\sq}{\sq}}
\can{\acc{p}{\dq}{\sq}}
\can{\acc{p}{\sq}{\dq}}
\can{\acc{p}{\dq}{\dq}}
\can{\acc{d}{\sq}{\sq}}
\can{\acc{d}{\dq}{\sq}}
\can{\acc{d}{\sq}{\dq}}
\can{\acc{d}{\dq}{\dq}}
\]
\end{center}
\end{document}
编辑
我考虑了@Mico的建议,分别将命令\overset
和\underset
改为\myoverset
和\myunderset
。还编辑了\texttt{}
主要新环境定义内的指令。
答案2
或者stackengine
:
\documentclass{article}
\usepackage[T1]{fontenc} % access \textquotedbl
\usepackage{textcomp} % access \textquotesingle
\usepackage{cancel}
\usepackage{stackengine}
\newlength{\dheight}
\newlength{\pdepth}
\newcommand{\abo}[2]{\stackinset{c}{}{c}{8pt}{#1}{\mbox{\vline height \dheight depth \pdepth width 0pt #2}}}
\newcommand{\bel}[2]{\stackinset{c}{}{c}{-10pt}{#1}{\mbox{\vline height 10pt depth \pdepth width 0pt #2}}}
\begin{document}
Normal text:
\settowidth{\dheight}{\heightof{d}}
\settowidth{\pdepth}{\depthof{p}}
\abo{'}{d}
\abo{\textquotedblright}{d}
\abo{'}{p}
\abo{\textquotedblright}{p}
\bel{'}{d}
\bel{\textquotedblright}{d}
\bel{'}{p}
\bel{\textquotedblright}{p}
\cancel{\abo{'}{d}}
\cancel{\abo{\textquotedblright}{d}}
\cancel{\abo{'}{p}}
\cancel{\abo{\textquotedblright}{p}}
\cancel{\bel{'}{d}}
\cancel{\bel{\textquotedblright}{d}}
\cancel{\bel{'}{p}}
\cancel{\bel{\textquotedblright}{p}}
\ttfamily
ttfamily:
\settowidth{\dheight}{\heightof{d}}
\settowidth{\pdepth}{\depthof{p}}
\abo{\textquotesingle}{d}
\abo{"}{d}
\abo{\textquotesingle}{p}
\abo{"}{p}
\bel{\textquotesingle}{d}
\bel{"}{d}
\bel{\textquotesingle}{p}
\bel{"}{p}
\cancel{\abo{\textquotesingle}{d}}
\cancel{\abo{"}{d}}
\cancel{\abo{\textquotesingle}{p}}
\cancel{\abo{"}{p}}
\cancel{\bel{\textquotesingle}{d}}
\cancel{\bel{"}{d}}
\cancel{\bel{\textquotesingle}{p}}
\cancel{\bel{"}{p}}
\sffamily
sffamily:
\settowidth{\dheight}{\heightof{d}}
\settowidth{\pdepth}{\depthof{p}}
\abo{'}{d}
\abo{"}{d}
\abo{'}{p}
\abo{"}{p}
\bel{'}{d}
\bel{"}{d}
\bel{'}{p}
\bel{"}{p}
\cancel{\abo{'}{d}}
\cancel{\abo{"}{d}}
\cancel{\abo{'}{p}}
\cancel{\abo{"}{p}}
\cancel{\bel{'}{d}}
\cancel{\bel{"}{d}}
\cancel{\bel{'}{p}}
\cancel{\bel{"}{p}}
\end{document}
答案3
像这样吗?(您发布的截图不太容易理解……)
\documentclass{article}
\usepackage[T1]{fontenc} % access \textquotedbl
\usepackage{textcomp} % access \textquotesingle
\usepackage{amsmath} % for "\text" macro
\usepackage{accents} % for "\accentset" and "\underaccent" macros
\def\dsquoteup{$\accentset{\text{\textquotesingle}}{\text{d}}$}
\def\ddquoteup{$\accentset{\text{\textquotedbl}}{\text{d}}$}
\def\psquoteup{$\accentset{\text{\textquotesingle}}{\text{p}}$}
\def\pdquoteup{$\accentset{\text{\textquotedbl}}{\text{p}}$}
\def\dsquotedn{$\underaccent{\text{\textquotesingle}}{\text{d}}$}
\def\ddquotedn{$\underaccent{\text{\textquotedbl}}{\text{d}}$}
\def\psquotedn{$\underaccent{\text{\textquotesingle}}{\text{p}}$}
\def\pdquotedn{$\underaccent{\text{\textquotedbl}}{\text{p}}$}
\begin{document}
\ttfamily
\dsquoteup\ddquoteup\psquoteup\pdquoteup \dsquotedn\ddquotedn\psquotedn\pdquotedn
\sffamily
\dsquoteup\ddquoteup\psquoteup\pdquoteup \dsquotedn\ddquotedn\psquotedn\pdquotedn
\end{document}