我想用箭头指向各种数字、各种数字格式和各种字体大小中的特定数字,但手动绘制每个箭头不是一个选项。出于演示目的,我已将所有箭头指向第一个数字,但我希望能够指向每个数字中的任何数字。有没有办法根据位值定位箭头?我通常使用 XeLaTeX 进行编译。
\documentclass[12pt,twoside]{article}
\usepackage[hmargin=19mm,vmargin=13mm,includeheadfoot,headheight=27.6pt,headsep=4mm]{geometry}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{tikz} \usepackage{tkz-euclide} \usetkzobj{all}
\usetikzlibrary{shadings,calc,positioning}
\usepackage{siunitx}
\sisetup{group-separator = {,},output-decimal-marker = {.}}
\usepackage{amsmath}
\usepackage{mathspec} \newfontfamily\myfont{Cambria}
\setallmainfonts{Cambria}
\setlength{\parindent}{0cm}
\usepackage{graphicx} \graphicspath{{Default/}}
\begin{document}
\begin{tikzpicture}[font=\fontsize{18}{18}\selectfont]
\node[left] at (0,0) {\fontsize{12}{12}\selectfont \textcolor{Gray}{1.}}; \node[right] at (0,0) {\num{976867695082.87}}; \draw[ultra thick,->] (0.35,-1) -- (0.35,-0.35);
\node[left] at (0,-2.1) {\fontsize{12}{12}\selectfont \textcolor{Gray}{2.}}; \node[right] at (0,-2.1) {\num{9772.9216}}; \draw[ultra thick,->] (0.35,-3.1) -- (0.35,-2.45);
\node[left] at (0,-4.2) {\fontsize{12}{12}\selectfont \textcolor{Gray}{3.}}; \node[right] at (0,-4.2) {\num{115698983.3302}}; \draw[ultra thick,->] (0.35,-5.2) -- (0.35,-4.55);
\node[left] at (0,-6.3) {\fontsize{12}{12}\selectfont \textcolor{Gray}{4.}}; \node[right] at (0,-6.3) {\num{61074171.8288}}; \draw[ultra thick,->] (0.35,-7.3) -- (0.35,-6.65);
\node[left] at (0,-8.4) {\fontsize{12}{12}\selectfont \textcolor{Gray}{5.}}; \node[right] at (0,-8.4) {\num{81872.56}}; \draw[ultra thick,->] (0.35,-9.4) -- (0.35,-8.75);
\node[left] at (0,-10.5) {\fontsize{12}{12}\selectfont \textcolor{Gray}{6.}}; \node[right] at (0,-10.5) {\num{118010166.2449}}; \draw[ultra thick,->] (0.35,-11.5) -- (0.35,-10.85);
\node[left] at (0,-12.6) {\fontsize{12}{12}\selectfont \textcolor{Gray}{7.}}; \node[right] at (0,-12.6) {\num{1036600250.575}}; \draw[ultra thick,->] (0.35,-13.6) -- (0.35,-12.95);
\sisetup{group-separator = {.},output-decimal-marker = {,}}
\node[left] at (0,-14.7) {\fontsize{12}{12}\selectfont \textcolor{Gray}{8.}}; \node[right] at (0,-14.7) {\num{271528084.6175}}; \draw[ultra thick,->] (0.35,-15.7) -- (0.35,-15.05);
\node[left] at (0,-16.8) {\fontsize{12}{12}\selectfont \textcolor{Gray}{9.}}; \node[right] at (0,-16.8) {\num{3591829.37023}}; \draw[ultra thick,->] (0.35,-17.8) -- (0.35,-17.15);
\node[left] at (0,-18.9) {\fontsize{12}{12}\selectfont \textcolor{Gray}{10.}}; \node[right] at (0,-18.9) {\num{4735855358.70}}; \draw[ultra thick,->] (0.35,-19.9) -- (0.35,-19.25);
\node[left] at (8.5,0) {\fontsize{12}{12}\selectfont \textcolor{Gray}{11.}}; \node[right] at (8.5,0) {\num{6162795621.24653}}; \draw[ultra thick,->] (8.85,-1) -- (8.85,-0.35);
\node[left] at (8.5,-2.1) {\fontsize{12}{12}\selectfont \textcolor{Gray}{12.}}; \node[right] at (8.5,-2.1) {\num{95475.63}}; \draw[ultra thick,->] (8.85,-3.1) -- (8.85,-2.45);
\node[left] at (8.5,-4.2) {\fontsize{12}{12}\selectfont \textcolor{Gray}{13.}}; \node[right] at (8.5,-4.2) {\num{18964906.93874}}; \draw[ultra thick,->] (8.85,-5.2) -- (8.85,-4.55);
\node[left] at (8.5,-6.3) {\fontsize{12}{12}\selectfont \textcolor{Gray}{14.}}; \node[right] at (8.5,-6.3) {\num{424743070.9}}; \draw[ultra thick,->] (8.85,-7.3) -- (8.85,-6.65);
\node[left] at (8.5,-8.4) {\fontsize{12}{12}\selectfont \textcolor{Gray}{15.}}; \node[right] at (8.5,-8.4) {\num{6886.7}}; \draw[ultra thick,->] (8.85,-9.4) -- (8.85,-8.75);
\sisetup{group-separator = {\,},output-decimal-marker = {,}}
\node[left] at (8.5,-10.5) {\fontsize{12}{12}\selectfont \textcolor{Gray}{16.}}; \node[right] at (8.5,-10.5) {\num{7038.187}}; \draw[ultra thick,->] (8.85,-11.5) -- (8.85,-10.85);
\node[left] at (8.5,-12.6) {\fontsize{12}{12}\selectfont \textcolor{Gray}{17.}}; \node[right] at (8.5,-12.6) {\num{944938652566.421}}; \draw[ultra thick,->] (8.85,-13.6) -- (8.85,-12.95);
\node[left] at (8.5,-14.7) {\fontsize{12}{12}\selectfont \textcolor{Gray}{18.}}; \node[right] at (8.5,-14.7) {\num{2927184.8}}; \draw[ultra thick,->] (8.85,-15.7) -- (8.85,-15.05);
\node[left] at (8.5,-16.8) {\fontsize{12}{12}\selectfont \textcolor{Gray}{19.}}; \node[right] at (8.5,-16.8) {\num{8376.65}}; \draw[ultra thick,->] (8.85,-17.8) -- (8.85,-17.15);
\node[left] at (8.5,-18.9) {\fontsize{12}{12}\selectfont \textcolor{Gray}{20.}}; \node[right] at (8.5,-18.9) {\num{235261584236.51}}; \draw[ultra thick,->] (8.85,-19.9) -- (8.85,-19.25);
\end{tikzpicture}
\clearpage
\end{document}
答案1
我不太确定这是否能回答您的确切问题,但这是我使用xstring
和tikzmark
包的建议。
基本上做的\addbelowarrow
是
- 取一个字符串
str
和一个字符位置index
- 分成
str
三个字符串(str(1:index-1)
,,,抱歉str(index)
,str(index+1:end)
使用了 matlab 符号) - 在角色 a 位置添加 tikz 标记
index
- 像什么都没发生一样打印字符串字符
- 画一个垂直箭头指向
index
我相信应该有更好的选择,但这是我能想到的唯一解决方案。
注意,需要编译两次才能工作
\documentclass{article}
\usepackage{xstring}
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\newcommand{\addbelowarrow}[2]{%
\pgfmathtruncatemacro{\charbefore}{#2-1}
\pgfmathtruncatemacro{\charafter}{#2+1}
\StrMid{#1}{1}{\charbefore}%
\tikzmarknode{tempnode}{\StrChar{#1}{#2}}%
\StrMid{#1}{\charafter}{100}%
\tikz[overlay,remember picture]{\draw[stealth-] (tempnode) --++ (0,-2em);}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\begin{itemize}
\item 123456789
\item \addbelowarrow{123456789}{4}
\item \addbelowarrow{123456789}{4}
\item \addbelowarrow{123456789}{2}
\item \addbelowarrow{123456789}{7}
\item \addbelowarrow{123456.789}{7}
\end{itemize}
\end{document}
答案2
这不是一个太严肃的答案。就像 BambOo 的漂亮答案一样,它使用xtring
。但是,它使用 来排版数字siunitx
。可以针对特定的 SI 设置重建数字的水平位置。这意味着,如果您更改设置,除非您相应地更改 pgf 函数,否则下面的内容很可能无法正常工作。您可以说
\path (0,0) node[name=test1,si node={76867695082.87}];
创建一个节点。然后数字位置存储在坐标中test1-digit1
,依此类推。
\documentclass{article}
\usepackage{siunitx}
\usepackage{tikz}
\sisetup{group-separator = {,},output-decimal-marker = {.}}
\usepackage{xstring}
\pgfmathdeclarefunction{punctuationcontribution}{2}{\begingroup
\pgfmathparse{(#2<5 ? 0 : int((#1-Mod(#2,3)+3*(Mod(#2,3)==2))/3)*2.7778)}%
\pgfmathsmuggle\pgfmathresult
\endgroup}
\pgfmathdeclarefunction{simarkpos}{2}{\begingroup
\pgfmathsetmacro{\digitwidth}{width("\num{1}")}%
\pgfmathsetmacro{\dotwidth}{width("\num{1.2}")-2*\digitwidth}%
\StrPosition{#1}{.}[\dotpos]%
\ifnum#2=\dotpos
\pgfmathparse{punctuationcontribution(#2,\dotpos)+(#2-1)*5+2.7778/2}%
\else
\ifnum#2<\dotpos
\pgfmathparse{punctuationcontribution(#2,\dotpos)+(#2-1)*5+5/2}%
\else
\pgfmathparse{punctuationcontribution(\dotpos-1,\dotpos)+(#2-1)*5+2.7778+5/2}%
\fi
\fi
\pgfmathsmuggle\pgfmathresult
\endgroup}
\tikzset{measure si node/.code={%
\StrLen{#1}[\mylen]%
\foreach \XX in {1,...,\mylen}
{\pgfmathsetmacro{\mydist}{simarkpos("#1",\XX)}
\path ([xshift=\mydist pt]\tikzlastnode.south west) coordinate
(\tikzlastnode-digit \XX);
}},
si node/.style={inner sep=0pt,node contents={\num{#1}},
append after command={[measure si node={#1}]}}}
\begin{document}
\begin{tikzpicture}
\path (0,0) node[name=test1,si node={76867695082.87}];
\foreach \X in {1,...,13}
{\draw[thin,stealth-] (test1-digit \X) -- ++ (0,-0.25)
node[below,font=\tiny\sffamily]{\X};}
\path (4,0) node[name=test2,si node={976867695082.87}];
\foreach \X in {1,...,14}
{\draw[thin,stealth-] (test2-digit \X) -- ++ (0,-0.25)
node[below,font=\tiny\sffamily]{\X};}
\path (8,0) node[name=test3,si node={1976867695082.87}];
\foreach \X in {1,...,15}
{\draw[thin,stealth-] (test3-digit \X) -- ++ (0,-0.25)
node[below,font=\tiny\sffamily]{\X};}
\end{tikzpicture}
\end{document}