1

我想在 Latex 中创建一个与此类似的图形(但在块中也有百分比):

在此处输入图像描述

我设法做到了这一点(MWE):


\documentclass{article}
\usepackage[latin1]{inputenc}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\usetikzlibrary{arrows,calc,positioning}
\usepackage{xcolor}


\usepackage{verbatim}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{5pt}%

\begin{document}
\tikzset{
    train/.style={
        text=black,
        draw,
        minimum height=1cm,
        minimum width=7cm,
        left color=orange, right color=orange!30!white,shading angle=90},
    val/.style={
        draw,
        text=black,
        minimum height=1cm,
        minimum width=2cm,
        left color=orange!30!white, right color=green!30!white,shading angle=90},
    test/.style={
        draw,
        text=black,
        fill=cyan,
        minimum height=1cm,
        minimum width=1cm}}
\begin{tikzpicture}[thin,black]
\path
(0,0)       node[train] (N) {70\%}
++(0:4.5)     node[val] (C) {20\%}
+(0:2)    node[test] (O) {10\%};

\end{tikzpicture}  
\end{document}

结果是: 在此处输入图像描述

显然,带有训练、验证和测试描述的箭头仍然缺失,我无法找到如何创建它。

我该怎么办?

谢谢!

4

1 回答 1

3

通常我会建议decorations.pathreplacing图书馆为 tikz 图片添加大花括号,但在这个特殊的淤泥中,画一些圆角的路径可能更容易:

\documentclass{article}
\usepackage[latin1]{inputenc}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\usetikzlibrary{arrows,calc,positioning}
\usepackage{xcolor}


\usepackage{verbatim}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{5pt}%

\begin{document}
\tikzset{
    train/.style={
        text=black,
        draw,
        minimum height=1cm,
        minimum width=7cm,
        left color=orange, right color=orange!30!white,shading angle=90},
    val/.style={
        draw,
        text=black,
        minimum height=1cm,
        minimum width=2cm,
        left color=orange!30!white, right color=green!30!white,shading angle=90},
    test/.style={
        draw,
        text=black,
        fill=cyan,
        minimum height=1cm,
        minimum width=1cm}}
\begin{tikzpicture}[thin,black]
\path
(0,0)       node[train] (N) {70\%}
++(0:4.5)     node[val] (C) {20\%}
+(0:2)    node[test] (O) {10\%};
\draw[->,rounded corners=1mm] (-3.5,0.6) |- (0,1) -- ++(0,0.5);
\draw[->,rounded corners=1mm] (3.5,0.6) |- (0,1) -- ++(0,0.5);
\draw[->,rounded corners=1mm] (3.5,0.6) |- (4.5,1) -- ++(0,0.5);
\draw[->,rounded corners=1mm] (5.5,0.6) |- (4.5,1) -- ++(0,0.5);
\draw[->,rounded corners=1mm] (6,0.6) |- (6.5,1) -- ++(0,0.5);
\draw[->,rounded corners=1mm] (7,0.6) |- (6.5,1) -- ++(0,0.5);
\node at (0,1.7) {Train};
\node at (4.5,1.7) {Validation};
\node at (6.5,1.7) {Test};
\end{tikzpicture}  
\end{document}

在此处输入图像描述

于 2019-08-05T10:33:39.907 回答