Adding colour to your LaTeX documents can transform them from plain academic texts into visually engaging materials that better communicate your ideas. Whether you're highlighting important sections, creating eye-catching presentations, or simply wanting to break up large blocks of text, understanding how to work with colour in LaTeX opens up a world of formatting possibilities. The xcolor package serves as the primary tool for this task, offering extensive capabilities that go far beyond basic colour changes. This guide will walk you through everything you need to know about implementing colour in your LaTeX documents, from simple text colour changes to creating sophisticated custom colour schemes that suit your specific requirements.
Getting Started with the xcolor Package and Basic Colour Commands
Before you can start adding colour to your LaTeX documents, you need to load the appropriate package into your preamble. The xcolor package represents the most flexible and widely recommended option for handling colours, as it extends the capabilities of the basic color package with additional features and colour models. To begin using it, simply add the command usepackage with xcolor in your document's preamble. This single line gives you immediate access to a range of default colours including red, green, blue, cyan, magenta, yellow, black, gray, white, darkgray, lightgray, brown, lime, olive, orange, pink, purple, teal, and violet.
Loading and Configuring the xcolor Package for Your Document
The xcolor package becomes even more powerful when you configure it with additional options during loading. By passing options such as dvipsnames to the package, you can unlock access to sixty-eight additional CMYK colours that greatly expand your palette. If you need even more variety, the svgnames option provides one hundred and fifty-one RGB colours, whilst x11names offers an impressive three hundred and seventeen colour choices. These options are specified within square brackets when you load the package, allowing you to tailor the available colours to your document's needs. The system typically auto-detects the correct driver for your LaTeX engine, whether you're using pdftex, xetex, or luatex, so you rarely need to specify this manually unless you're working with a specialised setup.
Understanding the textcolor Command for Applying Colours to Text
Once you've loaded the xcolor package, applying colour to your text becomes straightforward through the textcolor command. This command takes two arguments: the first specifies which colour you want to use, whilst the second contains the text you wish to colour. For instance, if you wanted to make a particular word appear in red, you would place red in the first set of curly brackets and your chosen text in the second. This approach allows you to colour specific portions of text without affecting the surrounding content. Alternatively, the color command changes the text colour for everything that follows within the current group, which can be useful when you want to colour entire paragraphs or sections. Both commands work seamlessly in regular text mode and can be nested within other formatting commands to create exactly the effect you're looking for.
Creating Background Colours and Coloured Boxes in LaTeX
Beyond simply changing text colour, LaTeX provides several methods for creating coloured backgrounds and boxes that can help important information stand out in your documents. These tools are particularly valuable when you want to draw attention to warnings, tips, or key concepts that readers should notice immediately. The xcolor package includes built-in commands for creating these visual elements without requiring additional packages, though you can combine them with other tools for even more sophisticated effects.

Using colorbox for Simple Background Colours
The colorbox command creates a simple box with a coloured background behind your text. This command requires two arguments: the background colour you want to apply and the text that should appear within the coloured box. The resulting box fits tightly around the text content, creating a highlighted effect that makes the text pop off the page. This technique works particularly well for short phrases or individual words that you want to emphasise, such as warnings or important terms. You can use any of the named colours available through your xcolor configuration, or reference custom colours that you've defined elsewhere in your document. The colorbox command integrates smoothly with surrounding text, allowing you to place highlighted content inline without disrupting the flow of your paragraphs.
Implementing fcolorbox for Bordered Coloured Boxes
When you need additional visual separation, the fcolorbox command provides a bordered version of the coloured box. This command takes three arguments rather than two: the frame colour, the background colour, and the text content. By specifying different colours for the border and background, you can create sophisticated visual hierarchies that help readers navigate complex documents. The border adds an extra layer of emphasis that makes the boxed content even more prominent than a simple background colour alone. This approach is particularly effective for creating callout boxes, highlighting quotations, or marking sections that require special attention. You can experiment with contrasting colour combinations to find schemes that work well with your document's overall design whilst remaining accessible and easy to read.
Defining Custom Colours and Working with RGB Values
Whilst the named colours provided by xcolor cover many common needs, you'll often want to create custom colours that precisely match your branding, institution colours, or personal preferences. The package provides robust tools for defining new colours using various colour models, giving you complete control over every aspect of your document's appearance. This flexibility ensures that you're never limited to predefined options and can create exactly the visual style you envision.
Creating Bespoke Colours with the definecolor Command
The definecolor command serves as your primary tool for creating custom colours in LaTeX. This command requires three pieces of information: the name you want to give your new colour, the colour model you're using, and the specific colour specification within that model. For example, you might define a custom shade of dark red by specifying rgb as the model and providing three decimal values between zero and one that represent the red, green, and blue components respectively. Once you've defined a colour, you can use its name anywhere you would use a standard colour name, making it easy to maintain consistent colouring throughout your document. The definecolor approach is particularly valuable when you're working with specific brand guidelines or need to match colours from other materials exactly.
Utilising rgb colour models for precise colour control
The RGB colour model represents one of the most intuitive ways to specify colours, as it breaks down any colour into its red, green, and blue components. When using the lowercase rgb model, you specify each component as a decimal number between zero and one, where zero means no contribution from that colour and one means maximum intensity. For instance, a value like zero point eight, zero, zero would create a deep red with strong red component but no green or blue. The uppercase RGB model works similarly but uses integer values between zero and two hundred and fifty-five, which many people find more familiar from web design and graphics software. Beyond RGB, xcolor supports additional models including cmyk for print work, gray for greyscale documents, HTML for web colour codes, and even wave for specifying colours by their light wavelength. This variety of models ensures you can work in whichever colour space best suits your workflow and output requirements, whilst maintaining precise control over your document's appearance.