4

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
        \% & \% header & header \% \\
        \hline
        xxxxxxxxxxx & xxxxxxxxxxx & xxxxxxxxxxx \\
        \hline
    \end{tabular}
\end{document}

Table OK

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
        \% & \% header & header \% \\
        \hline
        xxxxxxxxxxx & xxxxxxxxxxx & xxxxxxxxxxx \\
        \hline
    \end{tabular}
\end{document}

Table OK

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

5
  • 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.
    – albert
    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.
    – AugSB
    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.
    – albert
    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.
    – albert
    Jun 6, 2018 at 11:17
  • Yes, that's my impression too
    – AugSB
    Jun 6, 2018 at 11:53

1 Answer 1

6

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
\% & \% header & header \% \\
\hline
xxxxxxxxxxx & xxxxxxxxxxx & xxxxxxxxxxx \\
\hline
\end{tabular}

\end{document}

enter image description here

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
\% & \% header & header \% \\
\hline
xxxxxxxxxxx & xxxxxxxxxxx & xxxxxxxxxxx \\
\hline
\end{tabular}

\end{document}
5
  • Would your recommendation be that your redefinition would be incorporated into the Spanish babel version?
    – albert
    Jun 6, 2018 at 11:57
  • 1
    @albert I've already mailed the maintainer for this issue.
    – egreg
    Jun 6, 2018 at 12:07
  • Perfect (so I don't have to submit an issue anymore).
    – albert
    Jun 6, 2018 at 12:11
  • Thank you! I guess I just found my first bug in Latex... So proud of myself :)
    – AugSB
    Jun 6, 2018 at 12:14
  • 1
    @AugSB Yes, you found a bug :). I'll fix it. Jun 6, 2018 at 14:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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