1

I want to align text after some words. I followed this answer by @Torbjørn T. But there were error messages. Here is the code:

\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}

The error messages are as below:

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

How can this be solved?

I am using MiKTeX and PDFLaTeX.

4
  • 1
    Can show an image or sketch of what you are trying to achieve? Nov 6, 2020 at 15:05
  • 2
    You can't enclose different cells in the same \textcolor command.
    – campa
    Nov 6, 2020 at 15:05
  • @StevenB.Segletes Like the one in this question. Instead of black, the text would be in blue or any other color.
    – Imran
    Nov 6, 2020 at 16:06
  • @campa, thanks, it worked.
    – Imran
    Nov 6, 2020 at 16:08

1 Answer 1

1

Basically your problem is that you cannot open text color with \textcolor{blue}{ and then start the next cell (with &). You have to close \textcolor{blue}{} first then start the next cell.

Either you wanted do to the first column Name of the Experiment: in blue then you have to do it like this, and close the textcolor earlier:

\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}

or you wanted to have all the text in the table blue. Then you wrap the table in a seperate group like this:

\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}

Have a look at the xcolor documentation - you can also change the background color of the rows.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.