具有渐变填充和文本的圆角矩形

具有渐变填充和文本的圆角矩形

努力绘制以下图像。任何帮助都将不胜感激。以下是我的代码

\documentclass[10pt,journal,compsoc]{IEEEtran}

\usepackage{pgfplots}
\usepackage{subfig}
\usepackage{tcolorbox}
%\usepackage{adjustbox}

\usetikzlibrary{positioning,shapes,arrows,shadows,patterns,calc}

% correct bad hyphenation here
\hyphenation{op-tical net-works semi-conduc-tor}

\begin{document}
\begin{figure}
    \centering
    \begin{tikzpicture}[
    myrectangle/.style={rectangle, draw, minimum width=160, minimum 
 height=40, ultra thick, rounded corners=10, green}
    ]   
    \node[myrectangle] (a) at (0,0) {Energy Efficiency Applications};
    \node[myrectangle, right=0 of a] (b) {Less use of buffers and registers 
 instruction set optimization};
    \end{tikzpicture}
    \begin{tikzpicture}[
    myrectangle/.style={rectangle, draw, minimum width=160, minimum 
height=40, ultra thick, rounded corners=10, blue}
    ]   
    \node[myrectangle] (a) at (0,0) {Power Aware Resource Management};
    \node[myrectangle, right=0 of a] (b) {Energy aware task scheduling and 
resource provisioning policies};
    \end{tikzpicture}
\end{figure}    
\end{document}

在此处输入图片描述

答案1

tcbraster我认为使用或tcbitemize(来自)可以轻松绘制此类图表tcolorbox。框宽度会自动计算(\texwidth 除以列数),并且使用和raster equal height=rows两次编译可获得一行中所有框的相等高度。而且代码更简单。

\documentclass{article}
\usepackage{lmodern}
\usepackage[most]{tcolorbox}
\usetikzlibrary{shadings}

\tcbset{
    mybox/.style={
        enhanced,
        notitle,
        colframe=#1!80!black,
        interior style={top color=#1!5, bottom color=#1!30},
        fontupper=\bfseries,
        halign=flush center,
        valign=center
    },
    myraster/.style={
        raster equal height=rows,
        raster row skip=0pt,
        raster column skip=0pt,
        raster row 1/.style={mybox=green},
        raster row 2/.style={mybox=cyan},
        raster row 3/.style={mybox=red}
    }
}
\begin{document}

\begin{tcbitemize}[myraster]
\tcbitem Energy Efficiency Applications
\tcbitem Less use of buffers and registers, instruction set optimization, etc.
\tcbitem Power Aware Resource Management
\tcbitem Energy aware task scheduling and resource provisioning policies
\tcbitem Hardware Energy Efficiency
\tcbitem Clock frequency, voltage supply, logical gates, transistors, etc.
\end{tcbitemize}

\end{document}

在此处输入图片描述

答案2

  • minimum width设置具有和的节点的大小minimum height
  • 将颜色作为参数传递给新定义的样式mynode
  • 使用top colorbottom color进行颜色渐变。
  • 用于align=center, text width=35mm允许自动换行并获取居中文本。

代码:

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{positioning}

\begin{document}
    \begin{figure}
        \begin{tikzpicture}[
            node distance=0pt,
            mynode/.style={
                ultra thick, rectangle, rounded corners=5, draw=#1,
                minimum width=40mm, minimum height=14mm,
                align=center, text width=35mm, text=black,
                top color=white, bottom color=#1!40!white
            }
        ]

            \node[mynode=green] (a) at (0,0) {\textbf{A asdf qwer asdf qwer asdf}};
            \node[mynode=green, right=of a] (b) {B};

            \node[mynode=blue, below=of a] (c) {C};
            \node[mynode=blue, right=of c] (d) {D};

            \node[mynode=red, below=of c] (e) {E};
            \node[mynode=red, right=of e] (f) {F};
        \end{tikzpicture}
    \end{figure}
\end{document}

结果:

在此处输入图片描述

相关内容