如何更改乳胶中表格的元素颜色

如何更改乳胶中表格的元素颜色

如何将表格中的 2021-2022 改为红色

\documentclass{article}
\usepackage{tabularx} 

\begin{document}
    \begin{tabular}{cl}
    Year 2023-2024 & Very long very long text Very long very long text Very long very long text  \\
    Year 2022-2023 & Very long very long text Very long very long text Very long very long text \\
    Year 2021-2022 & Very long very long text Very long very long text Very long   \\
    Year 2020-2021 & Very long very long text Very long very long text Very long very long text  \\
    Year 2019-2020 & Very long very long text Very long very long text Very long very long text Very long very long text Very long very long text Very long very long text  \\
    Year 2018-2019 & Very long very long text Very long very long text Very long very long text Very long very long text Very long very long text Very long very long text  \\
    \end{tabular}
\end{document}

答案1

您可以使用\textcolor命令来为文本着色。如果要为单元格的背景着色,可以使用命令,\cellcolor如下面的 MWE 所示。我还用环境替换了tabulartabularx因为您已经加载了tabularx包),以便摆脱过满的框:

在此处输入图片描述

\documentclass{article}
\usepackage[table]{xcolor} % <--- table option only needed if you want to color the background of a cell
\usepackage{tabularx} 

\begin{document}
    \begin{tabularx}{\linewidth}{cX}
    Year 2023-2024 & Very long very long text Very long very long text Very long very long text  \\
    Year 2022-2023 & Very long very long text Very long very long text Very long very long text \\
    \textcolor{red}{Year 2021-2022} & Very long very long text Very long very long text Very long   \\
    \cellcolor{red} Year 2020-2021 & Very long very long text Very long very long text Very long very long text  \\
    Year 2019-2020 & Very long very long text Very long very long text Very long very long text Very long very long text Very long very long text Very long very long text  \\
    Year 2018-2019 & Very long very long text Very long very long text Very long very long text Very long very long text Very long very long text Very long very long text  \\
    \end{tabularx}
\end{document}

相关内容