我正在尝试弄清楚如何用圆圈(好吧,椭圆)突出显示表格中的数字,理想情况下不要使用 tikz 的大量开销。以下内容,只是我不知道如何1根据文本=数字的高度和宽度自动调整文本=数字周围的省略号的大小和位置;以及 [2] 如何不让它干扰表格列的对齐。这容易还是困难?一如既往地感谢建议。
\documentclass[12pt]{standalone}
\usepackage{ellipse}
\usepackage{color}
\setlength{\unitlength}{12pt}%
%% should not interfere with placement of number in table.
\newcommand{\enumber}[1]{
\begin{picture}(0,0)
\linethickness{1.5pt}%
%% dimensions should be autosized (ideally, even height, but width is more important)
%% location needs to be vertically centered
\put(0,0.25){\color{red}\ellipse{2}{0.5}}%
\put(0,0){\makebox[0mm][c]{#1}}
\end{picture}
}
\begin{document}
\begin{tabular}{lcr}
Left & Center & Right \\
\hline
12.0 & 22.0 & 32.0 \\
1212.0 & 2222.0 & 3232.0 \\
\enumber{12.0} & 22.0 & 32.0 \\
1212.0 & \enumber{2222.0} & 3232.0 \\
1212.0 & 2222.0 & \enumber{3232.0} \\
\end{tabular}
\end{document}
答案1
这很简单。诀窍是使用overlay
和适当的,inner sep
以免干扰列对齐。
要获得纯picture
模式解决方案,请等待大卫卡莱尔。
\documentclass[12pt, border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{fit}
\usetikzlibrary{shapes}
\setlength{\unitlength}{12pt}
\newcommand{\enumber}[1]{%
\begin{tikzpicture}[remember picture]
\node[inner sep=0pt](a){#1};
\end{tikzpicture}%
\begin{tikzpicture}[overlay, remember picture]
\node[draw, red, fit=(a), ellipse, inner sep=1pt, line width=1.5pt]{};
\end{tikzpicture}%
}
\begin{document}
\begin{tabular}{lcr}
Left & Center & Right \\
\hline
12.0 & 22.0 & 32.0 \\
1212.0 & 2222.0 & 3232.0 \\
\enumber{12.0} & 22.0 & 32.0 \\
1212.0 & \enumber{2222.0} & 3232.0 \\
1212.0 & 2222.0 & \enumber{3232.0} \\
\end{tabular}
\end{document}
答案2
我为此使用纯 TikZ。
\documentclass[tikz,border=5mm]{standalone}
\begin{document}
\begin{tikzpicture}[xscale=2,yscale=.8]
\path
(0,1) node[right]{Left}
(0,0) node[right]{1}
(0,-1) node[right]{123}
(0,-2) node[right]{12345}
(1,1) node{Center}
(1,0) node{234}
(1,-1) node{45678}
(1,-2) node{1}
(2,1) node[left=0]{Right}
(2,0) node[left=0]{6789}
(2,-1) node[left=0]{89}
(2,-2) node[left=0]{789};
% customizing ellipse as needed
\draw[red,thick]
(0,0)+(0:.3) arc(0:360:.2 and .25)
(1,-1)+(0:.35) arc(0:360:.35 and .28)
(2,-2)+(0:.1) arc(0:360:.3 and .25);
\draw (-.25,.5)--+(0:2.5);
\end{tikzpicture}
\end{document}