Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}}}
share|improve this question
add comment

5 Answers

up vote 10 down vote accepted
\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}

enter image description here

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

share|improve this answer
    
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. –  Herbert 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? –  Herbert Jul 21 '11 at 10:40
show 4 more comments

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”.

share|improve this answer
    
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
add comment

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}}}
share|improve this answer
    
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}}}\phant‌​om{#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
show 4 more comments

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.

share|improve this answer
    
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
add comment

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.

share|improve this answer
    
I am actually using both bold and color. –  Li Wang Jul 21 '11 at 11:36
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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