How can I make change a text background in LaTeX? For example using Latex code

\textsc{Extra Curricular Achievements}\

I get enter image description here

However, I want the background of this heading to be changed so that it looks like this:- enter image description here

I want the background to be extended to the right upto line break. Please ignore the underline in the previous image. Thanks.


I prefer using tcolorbox thinking that in future you may want the background to be fashionable. I have given many options (which are not needed for this particular case) in the tcbset so that you can play with them to suit your needs.


    frame code={}
    center title,
    enlarge left by=0mm,
    arc=0pt,outer arc=0pt,

\textsc{Extra Curricular Achievements}

enter image description here

Here is another option using framed package.

\noindent\textsc{Extra Curricular Achievements}

enter image description here

Without extra packages:

{\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\textsc{Extra Curricular Achievements}}}


enter image description here

And convert it in to a macro:

\mybox{\textsc{Extra Curricular Achievements}}

| improve this answer | |
  • Thanks .. btw using the tcbset approach, what can be done to remove the surrouding box . – sairajat Oct 7 '13 at 8:14
  • @sairajat Sorry which box? I don't follow. – user11232 Oct 7 '13 at 10:37
  • the surrounding purple colored box . sorry for late reply. did it myself . Thanks anyways .. :) – sairajat Oct 13 '13 at 5:30
  • @sairajat Never mind. That is my style of putting a picture on this site. If you run my code, you won't get it :-) – user11232 Oct 13 '13 at 13:47

I know this question has been answered very extensively. But not what I wanted or thought was the question based on the title. Therefore if others get in here looking for a possibility for colouring behind a word than this snippet is much easier:




resulting in:

Color result of the above commands

This is possible by only adding \usepackage{xcolor}. Just some extra info :)

Colour Several Lines It is correct that the above methods does not work for several lines, if you to be more than one line you can do:

{\color{green} the text you want to write}

This can however also be wrapped in a function so it is easier to use several places during edits, e.g., for colouring new text or whatever:


| improve this answer | |
  • 21
    text inside \colorbox can not be split into several lines if it is too long. So the macro is most suited for coloring a few words. If you want to color several sentences which spread across several lines, it is better to use soul – jdhao Nov 22 '16 at 12:31
  • 2
    The given link have some illustrating examples about how to use the soul package. – jdhao Nov 22 '16 at 14:18
  • 3
    sorry for off-topic, but hard to resist: I like how LaTeX is not easy at all -- you need to use soul to put some colour behind some text. – xealits Jan 26 '17 at 15:34
  • 3
    Exactly what I needed, no immense amount of packages, no huge newcommands, simply the colorbox. Thanks mate! – Dennis May 12 '17 at 13:33
  • 9
    This example would have taken me fewer seconds to parse if you replaced the text "{blue}" with some other text. :) – CPBL Nov 9 '17 at 2:46

Just to add to the last comment. One can use the `minipage' environment to extend over several lines:


One line.

Another line.

The final line.
| improve this answer | |

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.