我想用右侧的箭头注释表格,表示(在本例中)计算机语言的运算符优先级降低。我熟悉另一种解决方案此处列出,这涉及将整个表格置于数学模式,但我想对文本和箭头的格式有更多的控制权,也许有一个带有文本的漂亮彩色的 tikz 箭头。
我当前的示例在 /rotatebox 中使用数学模式,但是箭头不是列高,正如我希望的那样。
\documentclass[10pt]{article}
\usepackage[portrait, margin=0.25in]{geometry}
\usepackage{inconsolata}
\usepackage[T1]{fontenc}
\renewcommand*\familydefault{\ttdefault}
\usepackage[fleqn]{amsmath}
\usepackage{booktabs}
\usepackage{multirow}
\begin{document}
\begin{tabular}{@{}l|llllllll@{}}
Unary & + & - & \textasciicircum &&&&&\multirow{6}*{\rotatebox[origin=c]{270}{$\underrightarrow{precedence}$}}\\
Multiplication & * & / & \% & << & >> & \& & \&\textasciicircum&\\
Addition & + & - & | & \textasciicircum &&&&\\
Comparison & == & != & < & <= & > & >= &&\\
Logical & \&\& &&&&&&&\\
& || &&&&&&&
\end{tabular}
\end{document}
答案1
这很容易实现pst-node
(家族成员pstricks
):将表放在postscript
环境中,在第一行和最后一行的末尾定义空节点,并用箭头连接它们。此外,箭头上的文本在数学模式下被记录下来,但作为真实文本:
\documentclass[10pt]{article}
\usepackage[portrait, margin=0.25in]{geometry}
\usepackage{inconsolata}
\usepackage[T1]{fontenc}
\renewcommand*\familydefault{\ttdefault}
\usepackage[fleqn]{amsmath}
\usepackage{booktabs}
\usepackage{multirow, rotating}
\usepackage{pst-node, auto-pst-pdf}
\begin{document}
\renewcommand\arraystretch{1.25}
\begin{postscript}
\begin{tabular}{@{}l|llllllll@{}}
Unary & + & - & \textasciicircum &&&&&\pnode{B}\\%
Multiplication & * & / & \% & << & >> & \& & \&\textasciicircum&\\
Addition & + & - & | & \textasciicircum &&&&\\
Comparison & == & != & < & <= & > & >= &&\\
Logical & \&\& &&&&&&&\\
& || &&&&&&&\pnode{E}
\end{tabular}
\psset{arrowinset=0.12, arrows=->, nrot=:U, shortput=nab, labelsep=2pt}
\ncline[linecolor=red, nodesepA=-10.5pt, nodesepB=-4.8pt]{B}{E}^{\colorbox{Pink3!60}{precedence}}
\ncline[offset=30pt, linecolor=blue ]{B}{E}\ncput*{\colorbox{LightSteelBlue1}{precedence}}
\end{postscript}
\end{document}
添加:另一段代码可以自动调整箭头的大小。它将表格放在一个框节点中,该节点与 12 个次级节点相关联,并且两个最右边的关联节点通过箭头连接:
\begin{postscript}
\psDefBoxNodes{T}{
\begin{tabular}{@{}l|llllllll@{}}
Unary & + & - & \textasciicircum &&&&& \\%
Multiplication & * & / & \% & << & >> & \& & \&\textasciicircum&\\
Addition & + & - & | & \textasciicircum &&&&\\
Comparison & == & != & < & <= & > & >= &&\\
Logical & \&\& &&&&&&&\\
& || &&&&&&&
\end{tabular}}
\psset{arrowinset=0.12, arrows=->, nrot=:U, labelsep=2pt}
\pcline[linecolor=red](T:tr)(T:br)
\naput[nrot=:U]{\colorbox{Pink3!30}{precedence}}%{T:Cr}
\end{postscript}