在單字後對齊文字時出錯

在單字後對齊文字時出錯

我想在一些單字之後對齊文字。我跟著這個答案作者:@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 文檔- 您也可以變更行的背景顏色。

相關內容