我想在某些单词后对齐文本。我遵循这个答案@Torbjørn T. 但出现了错误信息。代码如下:
\documentclass{report}
\usepackage{xcolor}
\usepackage{tabularx}
\begin{document}
\begin{tabularx}{\linewidth}{@{}lX@{}}
\textcolor{blue}{\textit{Name of the Experiment:} & Frequency Stability Study of a Power System blah blah blah}
\end{tabularx}
\end{document}
错误信息如下:
line 9: Missing } inserted. \end{tabularx}
line 9: Extra }, or forgotten \endgroup. \end{tabularx}
line 9: Missing } inserted. \end{tabularx}
line 9: Extra }, or forgotten \endgroup. \end{tabularx}
line 9: Missing } inserted. \end{tabularx}
line 9: Extra }, or forgotten \endgroup. \end{tabularx}
line 9: Overfull \hbox (15.0pt too wide) in paragraph
如何解决?
我正在使用 MiKTeX 和 PDFLaTeX。
答案1
基本上,您的问题是您无法使用 打开文本颜色,\textcolor{blue}{
然后启动下一个单元格(使用&
)。您必须\textcolor{blue}{}
先关闭,然后启动下一个单元格。
你想对第一列进行操作实验名称:为蓝色,则必须这样做,并尽早关闭文本颜色:
\documentclass{report}
\usepackage{xcolor}
\usepackage{tabularx}
\begin{document}
\begingroup
\begin{tabularx}{\linewidth}{@{}lX@{}}
\textcolor{blue}{\textit{Name of the Experiment:}} & Frequency Stability Study of a Power System blah blah blah
\end{tabularx}
\end{document}
或者你想让表格中的所有文本都变成蓝色。那么你可以将表格包装在一个单独的组中,如下所示:
\documentclass{report}
\usepackage{xcolor}
\usepackage{tabularx}
\begin{document}
\begingroup %%start wrapper group
\color{blue} %%assign textcolor
\begin{tabularx}{\linewidth}{@{}lX@{}}
\textit{Name of the Experiment:} & Frequency Stability Study of a Power System blah blah blah
\end{tabularx}
\endgroup%%end wrapper group
\end{document}
看看xcolor 文档- 您还可以更改行的背景颜色。