如何将表格中的一些文本(数字)包裹在椭圆形(椭圆形状)中?

如何将表格中的一些文本(数字)包裹在椭圆形(椭圆形状)中?

我按照例子这里并得到这个:

\documentclass[a4paper]{article}
\usepackage{amsmath,array,booktabs}
\usepackage{tikz}
\usetikzlibrary{calc}


\def\startCirc#1{\tikz[remember picture,overlay]\path node[inner sep=0, anchor=south] (st) {\textbf{#1}} coordinate (start) at (st.center);}%
\def\endCirc#1{\tikz[remember picture,overlay]\path node[inner sep=0, anchor=south] (en) {\textbf{#1}} coordinate (end) at (en.center);%
\begin{tikzpicture}[overlay, remember picture]%
\path (start);%
\pgfgetlastxy{\startx}{\starty}%
\path (end);%
\pgfgetlastxy{\endx}{\endy}%
\pgfmathsetlengthmacro{\xdiff}{\endx-\startx}%
\pgfmathsetlengthmacro{\ydiff}{\endy-\starty}%
\pgfmathtruncatemacro{\xdifft}{\xdiff}%
\pgfmathsetmacro{\xdiffFixed}{ifthenelse(equal(\xdifft,0),1,\xdiff)}%
\pgfmathsetmacro{\angle}{ifthenelse(equal(\xdiffFixed,1),90,atan(\ydiff/\xdiffFixed))}%
\pgfmathsetlengthmacro{\xydiff}{sqrt(abs(\xdiff^2) + abs(\ydiff^2))}%
\path node[draw,rectangle, rounded corners=2mm, dashed, rotate=\angle, minimum width=\xydiff+4ex, minimum height=2.5ex] at ($(start)!.5!(end)$) {};%
\end{tikzpicture}%
}


\begin{document}


\begin{tabular}{
>{$}l<{$}
cc|cc|cc
}
\toprule
    \{ \phi(\cdot)  ,  p(\cdot) \}^\dagger  &   1768  &   1768  &   765  &   765  &   986  &   986 \\
    \{ [\phi(t+h)  ,  p(h)]_3 \}            &   1720  &   1720  &   \startCirc{7}6\endCirc{7}  &   766  &   956  &   956 \\
    \{ \phi(\cdot)  ,  p(h_2) \}^\dagger    &   1720  &   1720  &   754  &   754  &   959  &   959 \\
\bottomrule
\end{tabular}

\end{document}

所需的输出是第二个,颜色并不重要。我认为当前的方法可能过于“复杂”而没有必要?

在此处输入图片描述

答案1

如果只突出显示一个条目,则不需要(不应该)使用那个复杂的宏。只需使用这个简单版本:

\newcommand\Mark[2][]{%
\tikz[baseline=(a.base)]{
\node[inner sep=0pt,outer sep=0pt](a){\phantom{#2}};  %% just to be defensive
\node[draw,red,thick,inner sep=1pt, ellipse,text=black,overlay,minimum width=\widthof{#2},#1]  {#2};%
}
}

记得加载 tikz 库shapes.geometric来获取ellipse形状。我建议改用rounded rectangleshapes shapes.misc

\documentclass[a4paper]{article}
\usepackage{amsmath,array,booktabs}
\usepackage{tikz}
\usetikzlibrary{calc,shapes.misc,shapes.geometric}
\newcommand\Mark[2][]{%
\tikz[baseline=(a.base)]{
\node[inner sep=0pt,outer sep=0pt](a){\phantom{#2}};  %% just to be defensive
\node[draw,red,thick,inner sep=2pt, rounded rectangle,text=black,overlay,minimum width=\widthof{#2},#1]  {#2};%
}
}


\begin{document}


\begin{tabular}{
>{$}l<{$}
cc|cc|cc
}
\toprule
    \{ \phi(\cdot)  ,  p(\cdot) \}^\dagger  &   1768  &   1768  &   765  &   765  &   986  &   986 \\
    \{ [\phi(t+h)  ,  p(h)]_3 \}            &   1720  &   1720  &   \Mark{7677777}  &   766  &   956  &   956 \\
    \{ \phi(\cdot)  ,  p(h_2) \}^\dagger    &   1720  &   1720  &   754  &   754  &   959  &   959 \\
\bottomrule
\end{tabular}

\end{document}

在此处输入图片描述

相关内容