创建带箭头注释的简单表格图

创建带箭头注释的简单表格图

许多投资基金说明书都有如下所示的简单风险图表,并附有注释:

在此处输入图片描述

如何在 TeX 中重现这种情况?我想用表格,但也许某种 tikz 图片可能更好。由于对 TeX 还很陌生,我不知道从哪里开始。

答案1

一种可能性是,使用 TikZ matrix of math nodes

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}

\definecolor{myblue}{RGB}{42,87,102}

\begin{document}

\begin{tikzpicture}
\matrix[
  matrix of math nodes,
  row sep=-\pgflinewidth,
  nodes={
    draw,
    text width=1cm,
    align=center,
    minimum height=30pt
  }
  ] (mat)
  {
    1 & 2 & |[fill=myblue,font=\color{white}]|3 & 4 & 5 & 6 & 7 \\
  };
\draw[<->,>=latex]
  ([yshift=20pt]mat-1-1.north west) 
    node[anchor=north west,font=\scriptsize,inner xsep=0pt] {Lower Reward Potential}
    node[anchor=south west,font=\scriptsize,inner xsep=0pt] {Lower Risk}
    --
  ([yshift=20pt]mat-1-7.north east)
    node[anchor=north east,font=\scriptsize,inner xsep=0pt] {Higher Reward Potential}
    node[anchor=south east,font=\scriptsize,inner xsep=0pt] {Higer Risk}
  ;
\end{tikzpicture}

\end{document}

在此处输入图片描述

答案2

两个不含 TikZ 的选项:

  1. 首先,使用一些定义的框和\xleftrightarrow

    \documentclass{article}
    \usepackage{xcolor}
    \usepackage{mathtools}
    
    \definecolor{myblue}{RGB}{42,87,102}
    
    \newcommand\MyBox[2][white]{\fcolorbox{black}{#1}{\rule[-0.35cm]{0pt}{1cm}\makebox[1cm]{{#2}}}}
    
    \begin{document}
    
    \begin{minipage}{\dimexpr7cm+14\fboxsep+11\fboxrule\relax}
    {\scriptsize Lower Risk\hfill Higher Risk\par\vskip-1.5ex}
    $\xleftrightarrow{\hspace*{\dimexpr7cm+40pt\relax}}$\par\vskip-0.45ex
    {\scriptsize Lower Reward Potential\hfill Higher Reward Potential\par\medskip}
    
    \MyBox{1}%
    \hspace*{-0.5\fboxrule}\MyBox{2}%
    \hspace*{-0.5\fboxrule}\MyBox[myblue]{\textcolor{white}{3}}%
    \hspace*{-0.5\fboxrule}\MyBox{4}%
    \hspace*{-0.5\fboxrule}\MyBox{5}%
    \hspace*{-0.5\fboxrule}\MyBox{6}%
    \hspace*{-0.5\fboxrule}\MyBox{7}%
    \end{minipage}
    
    \end{document}
    

    在此处输入图片描述

  2. 其次,使用tabularand \xleftrightarrow

    \documentclass{article}
    \usepackage[table]{xcolor}
    \usepackage{array}
    \usepackage{mathtools}
    
    \definecolor{myblue}{RGB}{42,87,102}
    
    \begin{document}
    
    {
    \renewcommand\arraystretch{2}
    \setlength\tabcolsep{0pt}
    \begin{tabular}{*{7}{|>{\centering\arraybackslash}p{1.5cm}}|}
    \multicolumn{7}{p{10.5cm}}{%
    {\scriptsize Lower Risk\hfill Higher Risk\par\vskip-3.5ex}
    $\xleftrightarrow{\hspace*{10.3cm}}$\par\vskip-0.45ex
    {\scriptsize Lower Reward Potential\hfill Higher Reward Potential\par\medskip}
    } \\[-3ex]
    \hline
    1 & 2 &\cellcolor{myblue}\textcolor{white}{3} & 4 & 5 & 6 & 7 \\
    \hline
    \end{tabular}
    }
    
    \end{document}
    

    在此处输入图片描述

答案3

另一个选择:MetaPost,这里是一个 LuaLaTeX 程序。

这里N给出了盒子的数量、n必须填充的盒子len以及h盒子的尺寸。可随意调整。

\documentclass{standalone}
\usepackage{luamplib}
    \mplibsetformat{metafun}
    \mplibtextextlabel{enable}
\usepackage{xcolor}
    \definecolor{myblue}{RGB}{42,87,102}
\begin{document}
\begin{mplibcode}
n := 3; N := 7; len := 2cm; h := 1.5cm;
beginfig(1);
    path box; box = origin -- (len, 0) -- (len, h) -- (0, h) -- cycle;
    draw subpath (3, 4) of box;
    for i = 1 upto N:
        draw image(
            if i <> n:
                draw subpath (0, 3) of box;
                label("{\huge" & decimal i & "}", center box);
            else:
                fill box withcolor \mpcolor{myblue}; draw box;
                label("{\huge" & decimal i & "}", center box) withcolor white;
            fi) shifted ((i-1)*len, 0);
    endfor;
    pair arrow_offset; arrow_offset := (0, h + \mpdim{1.5\bigskipamount});
    path arrow; arrow = (origin -- N*len*right) shifted arrow_offset; drawdblarrow arrow;
    labeloffset := 0bp; pair offset; offset = (0, 4bp);
    label.lrt("Lower Reward Potential", point 0 of arrow) shifted -offset;
    label.llft("Higher Reward Potential", point 1 of arrow) shifted -offset;
    label.urt("Lower Risk", point 0 of arrow) shifted offset;
    label.ulft("Higher Risk", point 1 of arrow) shifted offset;  
    setbounds currentpicture to boundingbox currentpicture enlarged 3mm;
endfig;
\end{mplibcode}
\end{document}

在此处输入图片描述

相关内容