2

What I need is basically this: How to use fontawesome with fixed width? but using the new fontawesome5 package.

There, they redefine \faicon command but it has been changed in the new version. Fontawesome5 defines \faIcon as:

\NewDocumentCommand\faIcon{s O{\str_use:N\l_fontawesome_style_str} m}{
  \fontawesome_use_icon:nn{#2}{#3\IfBooleanT{#1}{-alt}}
}

So, theoretically, this should work:

\documentclass{article}
\usepackage{fontspec}
\usepackage{fontawesome5}
\usepackage{xparse}

\RenewDocumentCommand\faIcon{s O{\str_use:N\l_fontawesome_style_str} m}{
  \makebox[1.5em][c] \fontawesome_use_icon:nn{#2}{#3\IfBooleanT{#1}{-alt}}
}

\begin{document}

\section{\faGraduationCap \textbackslash faGraduationCap}
\section{\faBook \textbackslash faBook}

\faGraduationCap \textbackslash faGraduationCap\par\noindent
\faBook \textbackslash publications

\end{document}

But it's not... so what is wrong?

  • 1
    fontawesome5 handles this differently. You would need to redefine an internal command. Better make a feature request to the author. – Ulrike Fischer Oct 12 '18 at 12:12

2 Answers2

4

Starting with fontawesome5 version 5.4.1, released on 2018-10-13, you can pass the option fixed to fontawesome5 to get all icons in fixed-width:

\documentclass{article}
\usepackage[fixed]{fontawesome5}

\begin{document}

\section{\faGraduationCap \string\faGraduationCap}
\section{\faBook \string\faBook}

\faGraduationCap \string\faGraduationCap\par\noindent
\faBook \string\faBook

\end{document}

enter image description here

3

To get the original commands to do this you would have to redefine internal commands. Better make a feature request for a suitable style.

But beside this you can define your own command:

\documentclass{article}
\usepackage{fontspec}
\usepackage{fontawesome5}
\usepackage{xparse}

\NewDocumentCommand\fixfaIcon{ m s}{\makebox[1.5em][c]{\IfBooleanTF{#2}{\csname fa#1\endcsname*}{\csname fa#1\endcsname}}}

\begin{document}

\section{\fixfaIcon{GraduationCap}\textbackslash faGraduationCap}
\section{\fixfaIcon{Book}\textbackslash faBook}

\fixfaIcon{GraduationCap}\textbackslash faGraduationCap\par\noindent
\fixfaIcon{Book}\textbackslash publications
\fixfaIcon{File}*  \fixfaIcon{File}
\end{document}

enter image description here

Ulrike Fischer
  • 327,261
  • This doesn't work with alternative icons, those that end with *. – Kris Doe Oct 12 '18 at 15:06
  • I added an edit. – Ulrike Fischer Oct 12 '18 at 15:16
  • [solid] and [regular] arguments functionality are missing. Adding an optional argument works: \NewDocumentCommand\fixfaIcon{msO{solid}}{\makebox[1.5em][c]{\IfBooleanTF{#2}{\csname fa#1\endcsname*}{\csname fa#1\endcsname}[#3]}} – Kris Doe Oct 12 '18 at 16:12
  • Another problem are icons with digits in their name and fixing them is more difficult. Anyway I would recommend using the \faIcon{book} syntax instead of \faBook for this. – Marcel Krüger Oct 13 '18 at 13:33