如何将表格中的 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 所示。我还用环境替换了tabular
(tabularx
因为您已经加载了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}