Text FormattingNew Command for bold Text on colored Background

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
rawlins02
Posts: 22
Joined: Tue Oct 07, 2008 6:56 pm

New Command for bold Text on colored Background

Post by rawlins02 »

I'm looking to define a command that will facilitate placement of bold text in a yellow background. Here is a start without the bold, that also fails to wrap. I've tried a number of options without much success.

Code: Select all

\def\comment{\colorbox{yellow}}{}
Suggestions please. Thanks.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

New Command for bold Text on colored Background

Post by Johannes_B »

In order to help you, we need more information. What is going to happen, if the text is longer than one line, or longer than one paragraph.

Can you supply those info in form of a compilable minimal example?

Have a look at mdframed or todonotes.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
rawlins02
Posts: 22
Joined: Tue Oct 07, 2008 6:56 pm

New Command for bold Text on colored Background

Post by rawlins02 »

Johannes_B wrote:In order to help you, we need more information. What is going to happen, if the text is longer than one line, or longer than one paragraph.

Can you supply those info in form of a compilable minimal example?
An example

Code: Select all

\documentclass{minimal}
\usepackage{color,comment}
\begin{document}
\def\comment{\colorbox{yellow}}{}

In the compiled output text in curly brackets extends beyond the right margin
\comment{ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZz}

\end{document}
Johannes_B wrote: Have a look at mdframed or todonotes.
I have explored both. Prefer a simple bold text in yellow background that wraps normally
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

New Command for bold Text on colored Background

Post by Johannes_B »

Well, than have a look at Cool Text Highlighting in LaTeX.

The simplest approach would be soul:

Code: Select all

\documentclass{article}
\usepackage[width=5.05cm]{geometry}
\usepackage{color,soul}

\begin{document}
\noindent\hl{Highlighting} text feels good.
You can draw attention of people to a \hl{word} or perhaps 
\hl{even a whole sentence that spans across multiple lines
in such a way that hyphenation etc. are not affected.}
\end{document}
Code taken from Caramdir.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
Post Reply