# Spanish Babel and cell alignment with percentage symbol

I realized that spanish option for the babel package produces a bad behavior of the percentage symbol when aligning cells of the tables.

This code produces the following table:

\documentclass{article}
\begin{document}
\begin{tabular}{|c|c|c|}
\hline
\hline
xxxxxxxxxxx & xxxxxxxxxxx & xxxxxxxxxxx \\
\hline
\end{tabular}
\end{document}


But, adding the Spanish babel package prduces this: This code produces the following table:

\documentclass{article}
\usepackage[spanish]{babel}
\begin{document}
\begin{tabular}{|c|c|c|}
\hline
\hline
xxxxxxxxxxx & xxxxxxxxxxx & xxxxxxxxxxx \\
\hline
\end{tabular}
\end{document}


What's going on? Is there any way to solve it?

• Did you look into the documentation? In chapeter 1 ther is something about a change in environment (of a.o. \%), but as the documentation is only available in Spanish I don't understand it. Jun 6, 2018 at 10:53
• Thank you. It seems the package adds a small space in front of the symbol, but I do not see the reason why the above happens. Anyway, using \percentsigninstead of \% solved it. Jun 6, 2018 at 11:02
• Even when a small space in front of it I don't think this problem should appear, my internal knowledge of LaTeX is not enough to see why and how to fix it but it looks like a bug to me. Please correct me when I'm wrong. Jun 6, 2018 at 11:07
• I had a small further look in the documentation and I think you refer to paragraph 5.2 of the documentation where some things are written about some special characters. Problem looks like it only occurs when the % is the first character, so still I think my previous comment is valid. Jun 6, 2018 at 11:17
• Yes, that's my impression too Jun 6, 2018 at 11:53

With babel-spanish, \% is redefined to first do \es@sppercent, which in turn starts doing \unskip.

In your context, this cancel the centering glue from the column template, so the centering glue on the other side pushes everything all the way left.

A possibly better definition of \es@sppercent is to issue \unskip only when the natural width of the preceding glue is positive, for instance with

10 \%


that the conventions want to be typeset with a thin space and not a normal space. We can check just the natural width with \ifdim\lastskip>\z@. This way, \fill glue will not be removed.

\documentclass{article}
\usepackage[spanish]{babel}

\makeatletter
\renewcommand\es@sppercent{%
\leavevmode
\ifdim\lastskip>\z@ \unskip\fi
\textormath{$\m@th\,$}{\,}%
}
\makeatother

\begin{document}

\begin{tabular}{|c|c|c|}
\hline
\hline
xxxxxxxxxxx & xxxxxxxxxxx & xxxxxxxxxxx \\
\hline
\end{tabular}

\end{document}


A possibly better approach is to remove the glue only if it has no infinite stretchability:

\documentclass{article}
\usepackage[spanish]{babel}
\usepackage{xpatch}

\makeatletter
\renewcommand\es@sppercent{%
\leavevmode
\ifnum\gluestretchorder\lastskip=\z@\unskip\fi
\textormath{$\m@th\,$}{\,}%
}
\makeatother

\begin{document}

\begin{tabular}{|c|c|c|}
\hline