Fonts & Character SetsBetter looking Percent Symbol

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

Better looking Percent Symbol

Post by Cham »

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 :

Code: Select all

\documentclass[12pt]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[french]{babel}
\usepackage{amsmath}

\begin{document}
This $v \approx 58\% \, c$ looks ugly to me.
\end{document}
Is there any other "better looking" percent symbols?

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Better looking Percent Symbol

Post by cgnieder »

“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:

Code: Select all

\documentclass[12pt]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[french]{babel}
\usepackage{amsmath}

\usepackage{graphicx}
\newcommand*\pct{\scalebox{.9}{\%}}

\begin{document}
This $v \approx 58\% \, c$ looks ugly to me.

This $v \approx 58\pct \, c$ looks ugly to me.
\end{document}
Alternatively you could choose another font where the sign is more to your liking. Maybe this one?

Code: Select all

\documentclass[12pt]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[french]{babel}
\usepackage{amsmath}

\usepackage{mathpazo}

\begin{document}
This $v \approx 58\% \, c$ looks ugly to me.

\end{document}
Regards
site moderator & package author
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Re: Better looking Percent Symbol

Post by Cham »

Aaah ! The first solution is the right one !

Thanks a lot ! 8-)
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Better looking Percent Symbol

Post by Cham »

Now this is weird.

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

Code: Select all

\documentclass[12pt,twoside,nofootinbib]{book}
\usepackage[T1]{fontenc}
\usepackage{microtype}
\usepackage{amsmath}
\usepackage{graphicx}

\newcommand*\pct{\scalebox{0.9}{\%}}

\begin{document}

Here, it works : $x = 2.0\pct$.

\begin{figure}
	Test
	\caption{Here, it gives a compilation error : $x = 1.0\pct$.}
\end{figure}

\end{document}
So what is happening here ?
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Better looking Percent Symbol

Post by Johannes_B »

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.

Code: Select all

\documentclass[12pt,twoside,
%nofootinbib%unknown
]{book}
\usepackage[T1]{fontenc}
\usepackage{microtype}
\usepackage{amsmath}
\usepackage{graphicx}

\newcommand*\pct{\protect\scalebox{0.9}{\%}}

\begin{document}

Here, it works : $x = 2.0\,\pct$.

\begin{figure}
	Test
	\caption{Here, it gives a compilation error : $x = 1.0\,\pct$.}
\end{figure}

\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: 937
Joined: Sat Apr 02, 2011 4:06 pm

Better looking Percent Symbol

Post by Cham »

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: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Better looking Percent Symbol

Post by Johannes_B »

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: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Better looking Percent Symbol

Post by cgnieder »

Johannes_B wrote:

Code: Select all

\newcommand*\pct{\protect\scalebox{0.9}{\%}}
Maybe it's easier and even more robust to make \pct itself robust:

Code: Select all

\DeclareRobustCommand*\pct{\scalebox{.9}{\%}}
Cham wrote:What is the \protect command doing ?
See also What is the difference between Fragile and Robust commands?

Regards :)
site moderator & package author
Post Reply