3

I'm using XelaTeX to typeset a table with a vocabulary list in a foreign language, with a structure similar to this one: different columns are typeset in different fonts (and scripts). It seems that this should be implemented with \newcolumntype from the array package.

Below is a MWE of my attempt to typeset one column in Linux Libertine and one in Arial:

%!TEX TS-program = xelatex
%!TEX encoding = UTF-8 Unicode
\documentclass[12pt, a4paper]{standalone}

\usepackage{fontspec}
\setmainfont{Linux Libertine O}

\usepackage{array}

\newcolumntype{L}{>{\fontspec{Linux Libertine O}}l}
\newcolumntype{A}{>{\fontspec{Arial}}l}

\begin{document}

\begin{tabular}{LA}
Libertine & Arial\\
\end{tabular}

\end{document}  

it defines columns of type L (to be typeset in Libertine) and A (Arial).

I get the following error message on compilation: ! Forbidden control sequence found while scanning use of \bool_if:nTF. <inserted text> \par l.16 Libertine & Arial\\

It seems that the syntax for \newcolumntype has changed recently, so based on the manual I tried to define the column as

\newcolumntype{L}{>{\fontspec{Linux Libertine O}}{l}<{}}

which results in the same error.

Any ideas?

1 Answer 1

6

You get the same error if you try to use >{\fontspec...} directly in the tabular. It is not a good idea to set up a font in this place (apart from the error, fontspec would have to do it again in every cell). Setup the fonts first and then use the normal font commands instead:

\documentclass[12pt, a4paper]{article}

\usepackage{fontspec}
\setmainfont{Linux Libertine O}
\setsansfont{Arial}
\newfontfamily\testfamily{Cambria}
\usepackage{array}

\newcolumntype{L}{>{\rmfamily}l}
\newcolumntype{A}{>{\sffamily}l}
\newcolumntype T{>{\testfamily}l}

\begin{document}

\begin{tabular}{LAT}
Libertine & Arial& Cambria\\
\end{tabular}

\end{document}  
2
  • 1
    Ok, so the error notwithstanding, TeX would run out of memory, right? Buty why the error in the first place?
    – MatteoS
    Oct 16, 2014 at 10:13
  • No, I don't think that TeX would run out of memory. But it is still a waste of time to recreate fonts again and again. \fontspec has an optional argument and the code explodes when it is looking if this argument is present. You can avoid the error by using >{\fontspec{Arial}[]} or >{\fontspec{Arial}\relax} but I don't recommend it. Oct 16, 2014 at 10:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .