为表格添加背景色:\rowcolor, \columncolor,\cellcolor

设置行的背景

\rowcolor 是 LaTeX 中用于设置表格行的背景色的命令。它可以使表格更加美观和易于阅读。rowcolor 命令通常与 colortbl 宏包一起使用。

语法如下:

\rowcolor{<color>}

其中 表示要设置的背景色,可以是预定义的颜色名称(如 red、blue)、RGB 值(如 RGB(255,0,0))、HTML 颜色代码(如 #FF0000)等。

例如,\rowcolor{gray} 将设置当前行的背景色为灰色。可以在表格的每行中使用 \rowcolor 命令来交替设置行的背景色,以提高表格的可读性。

请确保在文档的导言区正确加载 colortbl 宏包(使用 \usepackage{colortbl})才能使用 \rowcolor 命令.

例子:

\begin{table}[thb]\centering
    \caption{A table with parallel lines for grouping and color highlight.} %
    \label{tab:ablation_study}
    \resizebox{0.48\textwidth}{!}{
    \Large
    \begin{tabular}{*{2}{l}||*{2}{c}||*{2}{c}||*{2}{c}}
        \toprule
        \multicolumn{1}{c}{} & \multicolumn{1}{c||}{} & \multicolumn{2}{c||}{Synthetic Dataset} & \multicolumn{2}{c||}{Static Data} & \multicolumn{2}{c}{Dynamicgt Data} \\
        ID & Method  & PSNRT & VDP & PSNRT & VDP & PSNRT & VDP \\
        \midrule
        0 & ANet  & 39.25 & 70.81 & 40.62 & 74.51 & 44.43 & 77.74 \\ %
        1 & BNet  & 39.69 & 70.95 & 37.61 & 75.30 & 43.70 & 78.97 \\
        \rowcolor{gray!20}
        2 & ANet + BNet  & \textbf{40.34} & \textbf{71.79} & \textbf{41.18} & \textbf{76.15} & \textbf{45.46} & \textbf{79.09} \\
        \midrule
        3 & ANet + BNet w/o C & 39.72 & 71.38 & 40.52 & 74.79 & 45.09 & 78.24 \\ %
        4 & ANet + BNet w/o D & 40.03 & 71.66 & 40.80 & 76.12 & 45.17 & 78.99 \\ %
        \bottomrule
    \end{tabular}
    }
\end{table}

在这里插入图片描述

设置列的背景

要给表格中的某一列设置背景色,可以使用 colortbl 宏包中的 >{\columncolor{}} 命令。这个命令可以在表格中的某一列中设置背景色。

以下是具体步骤:

在导言区加载 colortbl 宏包:\usepackage{colortbl}。
在表格中指定列的格式时,在相应的列类型前添加 >{\columncolor{<color>}} ,其中 是要设置的背景色。
例如,如果要给第二列设置背景色为灰色,可以这样编写表格:

\documentclass{article}
\usepackage{colortbl}

\begin{document}

\begin{tabular}{|c|>{\columncolor{gray}}c|c|}
\hline
Header 1 & Header 2 & Header 3 \\
\hline
Cell 1 & Cell 2 & Cell 3 \\
Cell 4 & Cell 5 & Cell 6 \\
\hline
\end{tabular}

\end{document}

在这里插入图片描述

设置某单元格的背景

要给表格中的某一个单元格设置背景色,可以使用 colortbl 宏包中的 \cellcolor{} 命令。这个命令可以在表格中的特定单元格中设置背景色。

以下是具体步骤:

在导言区加载 colortbl 宏包:\usepackage{colortbl}。
在需要设置背景色的单元格中使用 \cellcolor{} 命令,其中 是要设置的背景色。
例如,假设您想要给表格中的第二行第三列的单元格设置背景色为浅蓝色,您可以这样编写表格:

\documentclass{article}
\usepackage{colortbl}

\begin{document}

\begin{tabular}{|c|c|c|}
\hline
Header 1 & Header 2 & Header 3 \\
\hline
Cell 1 & Cell 2 & \cellcolor{blue!25}Cell 3 \\
Cell 4 & Cell 5 & Cell 6 \\
\hline
\end{tabular}

\end{document}

在这里插入图片描述

  • 5
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一段使用Qt5.12.12绘制播放音乐动态直方图的源代码: ```cpp #include <QtWidgets> class MusicWidget : public QWidget { public: MusicWidget(QWidget *parent = nullptr) : QWidget(parent) { setFixedSize(400, 300); } void setAudioData(const QVector<double> &data) { audioData = data; update(); } protected: void paintEvent(QPaintEvent *event) override { Q_UNUSED(event); QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing); int columnWidth = width() / audioData.size(); // 绘制直方图 for (int i = 0; i < audioData.size(); ++i) { int columnHeight = height() * audioData[i]; QPoint topLeft(i * columnWidth, height() - columnHeight); QColor columnColor(Qt::red); columnColor.setAlphaF(0.5); painter.setBrush(columnColor); painter.drawRect(QRect(topLeft, QSize(columnWidth, columnHeight))); } } private: QVector<double> audioData; }; int main(int argc, char *argv[]) { QApplication app(argc, argv); // 生成随机音频数据 QVector<double> audioData; for (int i = 0; i < 100; ++i) { double value = qrand() / static_cast<double>(RAND_MAX); audioData.append(value); } MusicWidget musicWidget; musicWidget.setAudioData(audioData); musicWidget.show(); return app.exec(); } ``` 这段代码创建了一个名为`MusicWidget`的QWidget子类,用于绘制动态直方图。在构造函数中,设置了窗口的固定大小。`setAudioData`函数用于设置音频数据,当音频数据改变时,调用`update`函数触发重新绘制。 在`paintEvent`函数中,通过QPainter类进行绘制操作。首先,设置了绘制抗锯齿效果。然后,根据音频数据的大小,计算出每个直方图列的宽度。接着,使用循环遍历音频数据并绘制每个直方图列。绘制使用了Qt引擎中的QPainter类的drawRect函数,根据数据值计算出直方图的高度,并设定矩形的位置和尺寸。绘制完成后,显示窗口。 在main函数中,首先生成了一个随机音频数据,然后创建MusicWidget对象,并将音频数据设置到该对象中,最后显示窗口并启动应用程序的事件循环。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值