# \textbf{text} without increasing the length of the text

When using \textbf{text}, the length of text will be increased. Is there a way to make the text bold face without increasing its length?

edit:

Thanks to @Herbert and @Martin, here is a perfect solution for me:

   \newsavebox\CBox
\newcommand<>*\textBF[1]{\sbox\CBox{#1}\resizebox{\wd\CBox}{\ht\CBox}{\textbf#2{#1}}}


\documentclass{article}
\usepackage{graphicx}
\newsavebox\CBox
\def\textBF#1{\sbox\CBox{#1}\resizebox{\wd\CBox}{\ht\CBox}{\textbf{#1}}}
\parindent=0pt
\begin{document}
foobarbaz y\\
\textbf{foobarbaz} y\\
\textBF{foobarbaz} y

\end{document}


The example for beamer

\documentclass{beamer}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\newsavebox\CBox
\newcommand<>*\textBF[1]{\only#2{\sbox\CBox{#1}\resizebox{\wd\CBox}{\ht\CBox}{\textbf{#1}}}}
\parindent=0pt
\begin{document}
\begin{frame}{foo}
\only<1>{foobarbaz y1}
\textbf<2->{foobarbaz y2}
\textBF<3>{foobarbaz y3}
\end{frame}

\end{document}


Another (better) possibility is to use the letter spacing option from the package microtype

• is it possible to make it work with beamer overlays? --e.g.\textBF<1>{text} – Li Wang Jul 21 '11 at 10:06
• use it this way: \only<1>{\textBF{text}} or put this definition into \def\textBFitself. – user2478 Jul 21 '11 at 10:28
• It should be \newcommand<>\textBF[1]{\only#2{\sbox\CBox...}}, where the dots mean all the rest in Herbert's definition. – egreg Jul 21 '11 at 10:33
• @Herbert: Humm, using \only here will lead to a different effect in my situation --- i.e. the text will disappear in other slides. – Li Wang Jul 21 '11 at 10:36
• @Lee: then you do not have a \only<1-> so that it appears from slide 1 up to the end. Right? – user2478 Jul 21 '11 at 10:40

You can use \fontseries{b}\selectfont to select a non-extended bold font, provided of course that the font family you're using contains such a font (as computer modern does). For comparison, note that \textbf uses \fontseries{bx}, where the xstands for “extended”.

• In my opinion, the visual difference between Computer Modern's medium and non-extended-bold fonts isn't all that big. As a result, viewers of a beamer presentation might not even notice the intended effect of alternating between those two fonts. – Mico Jul 21 '11 at 10:41
• @Mico: You have a point there. I was in a hurry and hadn't noticed that this was for a beamer presentation (which wasn't clear from the question itself). But I'll let the answer stand for future reference, since this is an option that should at least be considered. – Harald Hanche-Olsen Jul 21 '11 at 11:15
• I agree, it's good to mention the option of using a non-extended bold form of the Computer Modern roman (serif) fonts. – Mico Jul 21 '11 at 11:51

You could use the following macro instead. It uses the size of the horizontal and vertical size of the normal text, but sets it as bold text which makes the bold text lap over the text which follows. The text is also not breakable any longer. For overlays of table cells this should be fine but I wouldn't use it in running text of course.

\newcommand*{\textBF}[1]{\rlap{\raisebox{0pt}[0pt][0pt]{\textbf{#1}}}\phantom{#1}}


If you want to support beamer overlays use:

\newcommand<>*{\textBF}[1]{\only#2{\rlap{\raisebox{0pt}[0pt][0pt]{\textbf{#1}}}\phantom}{#1}}


or

\newcommand<>*{\textBF}[1]{\alt#2{\rlap{\raisebox{0pt}[0pt][0pt]{\textbf{#1}}}\phantom{#1}}{\mbox{#1}}}

• Thank you very much! How did you know I am using it for overlays of table cells?...It seems that I couldn't use it in this way: \textBF<1>{text}? – Li Wang Jul 21 '11 at 9:18
• I tried to \newcommand*{\textBF}[2]{\rlap{\raisebox{0pt}[0pt][0pt]{\textbf<#1>{#2}}}\phantom{#2}} But it seems that it does not work. – Li Wang Jul 21 '11 at 9:26
• @Lee: see my update. – Martin Scharrer Jul 21 '11 at 9:29
• hummm, I am not sure whether it is working in my table. It seems that if the text of the \textBF{text} is at the end, the length of the cell is still affected. BTW, it seems that I couldn't mention your name... – Li Wang Jul 21 '11 at 9:38
• @Lee: Try the second version now. – Martin Scharrer Jul 21 '11 at 9:42

This answer is just for adding overlay support to Herber's command, who should credited for it.

\newcommand<>\textBF[1]{\only#2{\dotextBF}{#1}}
\newcommand\dotextBF[1]{\sbox0{#1}\resizebox{\wd0}{\ht0}{\textbf{#1}}}

...

\textBF<2->{xyz}


"xyz" will be bold from the second screen onwards.

I don't think it's a good way to emphasize things on screen; colors are better.

• I am actually using both bold and color. – Li Wang Jul 21 '11 at 11:36

If you're willing to (or allowed to) switch to typewriter (monospaced) font, you won't encounter the problem: the regular and bold fonts have glyphs of the exact same widths.

The following MWE uses Courier (scaled 5% in order to equate the cap-heights of the mono and text fonts in use), because in that font the difference between medium weight and bold is particularly strong. The lmodern package has a bold mono font as well, but the difference to the medium weight isn't as pronounced.

\documentclass{article}
\usepackage[scaled=1.05]{couriers} %%
\begin{document}
\noindent
\texttt{The quick brown fox 012456789}\\
\texttt{\bfseries The quick brown fox 012456789}
\end{document}


Another font package possibility you may want to consider is arev. (Given that you seem to be preparing for a beamer presentation, using the arev package would be a good choice anyway.) In the arev package, the mono font harmonizes well with the text font (which is a sans-serif font), and the medium and bold mono fonts are quite different.

• Yes, I can change the font. Could you please provide me with an example? – Li Wang Jul 21 '11 at 9:50
• @Lee: I've added an example to my answer above. – Mico Jul 21 '11 at 10:19
• is it possible to use this technique on my current font? – Li Wang Jul 21 '11 at 10:38
• Lee: What font family are you currently using? – Mico Jul 21 '11 at 11:40