LaTeX forum ⇒ Fonts & Character SetsBetter looking Percent Symbol Topic is solved

Information and discussion about fonts and character sets (e.g. how to use language specific characters)
User avatar
Cham
Posts: 894
Joined: Sat Apr 02, 2011 4:06 pm

Better looking Percent Symbol

Postby Cham » Fri Jun 15, 2012 5:15 pm

I know that the percent symbol is \% in LaTeX, but I don't like its appearance with a number close to it. It's a bit too big. See for example this code :
  1. \documentclass[12pt]{article}
  2. \usepackage[T1]{fontenc}
  3. \usepackage[utf8]{inputenc}
  4. \usepackage[french]{babel}
  5. \usepackage{amsmath}
  6.  
  7. \begin{document}
  8. This $v \approx 58\% \, c$ looks ugly to me.
  9. \end{document}

Is there any other "better looking" percent symbols?

User avatar
cgnieder
Site Moderator
Posts: 1988
Joined: Sat Apr 16, 2011 7:27 pm

Postby cgnieder » Sat Jun 16, 2012 5:03 pm

“better looking” is awfully subjective... If your goal is a smaller percent sign you can always scale it although this might not be the best solution:

  1. \documentclass[12pt]{article}
  2. \usepackage[T1]{fontenc}
  3. \usepackage[utf8]{inputenc}
  4. \usepackage[french]{babel}
  5. \usepackage{amsmath}
  6.  
  7. \usepackage{graphicx}
  8. \newcommand*\pct{\scalebox{.9}{\%}}
  9.  
  10. \begin{document}
  11. This $v \approx 58\% \, c$ looks ugly to me.
  12.  
  13. This $v \approx 58\pct \, c$ looks ugly to me.
  14. \end{document}


Alternatively you could choose another font where the sign is more to your liking. Maybe this one?
  1. \documentclass[12pt]{article}
  2. \usepackage[T1]{fontenc}
  3. \usepackage[utf8]{inputenc}
  4. \usepackage[french]{babel}
  5. \usepackage{amsmath}
  6.  
  7. \usepackage{mathpazo}
  8.  
  9. \begin{document}
  10. This $v \approx 58\% \, c$ looks ugly to me.
  11.  
  12. \end{document}


Regards
Clemens
------------------------------
chemmacros · chemformula · leadsheets · xsim

User avatar
Cham
Posts: 894
Joined: Sat Apr 02, 2011 4:06 pm

Postby Cham » Sat Jun 16, 2012 5:10 pm

Aaah ! The first solution is the right one !

Thanks a lot ! 8-)

User avatar
Cham
Posts: 894
Joined: Sat Apr 02, 2011 4:06 pm

Postby Cham » Sun Jan 17, 2016 7:17 pm

Now this is weird.

The above solution works very well, except when I'm using it inside a caption :

  1. \documentclass[12pt,twoside,nofootinbib]{book}
  2. \usepackage[T1]{fontenc}
  3. \usepackage{microtype}
  4. \usepackage{amsmath}
  5. \usepackage{graphicx}
  6.  
  7. \newcommand*\pct{\scalebox{0.9}{\%}}
  8.  
  9. \begin{document}
  10.  
  11. Here, it works : $x = 2.0\pct$.
  12.  
  13. \begin{figure}
  14. Test
  15. \caption{Here, it gives a compilation error : $x = 1.0\pct$.}
  16. \end{figure}
  17.  
  18. \end{document}


So what is happening here ?

User avatar
Johannes_B
Site Moderator
Posts: 3904
Joined: Thu Nov 01, 2012 4:08 pm

Postby Johannes_B » Sun Jan 17, 2016 7:46 pm

Some things like glass vases are sensible and can break when moving. You have to protect them from breaking using protection, for example using bubble wrap.
The same with LaTeX. Some commands in moving arguments are fragile, so you have to protect them.
  1. \documentclass[12pt,twoside,
  2. %nofootinbib%unknown
  3. ]{book}
  4. \usepackage[T1]{fontenc}
  5. \usepackage{microtype}
  6. \usepackage{amsmath}
  7. \usepackage{graphicx}
  8.  
  9. \newcommand*\pct{\protect\scalebox{0.9}{\%}}
  10.  
  11. \begin{document}
  12.  
  13. Here, it works : $x = 2.0\,\pct$.
  14.  
  15. \begin{figure}
  16. Test
  17. \caption{Here, it gives a compilation error : $x = 1.0\,\pct$.}
  18. \end{figure}
  19.  
  20. \end{document}
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.

User avatar
Cham
Posts: 894
Joined: Sat Apr 02, 2011 4:06 pm

Postby Cham » Sun Jan 17, 2016 8:19 pm

Ow ! What is the \protect command doing ? (well, I mean except to use some "bubbles" to protect the macro ! :lol: )

User avatar
Johannes_B
Site Moderator
Posts: 3904
Joined: Thu Nov 01, 2012 4:08 pm

Postby Johannes_B » Sun Jan 17, 2016 9:09 pm

Compare Section12.9 in texdoc latex2e, the unofficial reference manual.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.

User avatar
cgnieder
Site Moderator
Posts: 1988
Joined: Sat Apr 16, 2011 7:27 pm

Postby cgnieder » Mon Jan 18, 2016 12:57 pm

Johannes_B wrote:
  1. \newcommand*\pct{\protect\scalebox{0.9}{\%}}

Maybe it's easier and even more robust to make \pct itself robust:
  1. \DeclareRobustCommand*\pct{\scalebox{.9}{\%}}


Cham wrote:What is the \protect command doing ?

See also What is the difference between Fragile and Robust commands?

Regards :)
Clemens
------------------------------
chemmacros · chemformula · leadsheets · xsim


Return to “Fonts & Character Sets”

Who is online

Users browsing this forum: No registered users and 4 guests