2

Take the following code:

\documentclass{article}
\usepackage[oldstyle, tabular]{libertine}
\usepackage{array}
\newlength{\period}
\settowidth{\period}{9999--9999}

\begin{document}
    \begin{tabular}{>{\raggedleft}p{\period}l}
        2002--2005 & Put some text and numbers 0123456789 here
    \end{tabular}
\end{document}

enter image description here

In this example, I've defined the width of the left column (which is set to be ragged left) to be the width of eight tabular (i.e. monospaced) numerals and a hyphen.

But what I actually want is to set the width of the left column as above, but use proportional numerals outside of the first column. The example below obviously doesn't work, since this will set all numerals in the document to be proportional:

\documentclass{article}
\usepackage[oldstyle, proportional]{libertine} % <- change is here only
\usepackage{array}
\newlength{\period}
\settowidth{\period}{9999--9999}

\begin{document}
    \begin{tabular}{>{\raggedleft}p{\period}l}
        2002--2005 & Put some text and numbers 0123456789 here
    \end{tabular}
\end{document}

enter image description here

So my question is: How can I set the width of the first column to be based on tabular numerals, and then use tabular numerals in that column in the document, but use proportional numerals elsewhere?

If this is best done with fontspec, then I'm open to using that instead.

  • why not use an l column, why use a p column here? – David Carlisle Apr 20 '15 at 15:18
  • @DavidCarlisle Because I want the columns to line up with other tables in the same document in which the content of the first column doesn't match the width of 2002-2005. – Sverre Apr 20 '15 at 15:22
2

You can define a \tabfig command that chooses oldstyle digits in tabular format:

\documentclass{article}
\usepackage[
  oldstyle,
  proportional
]{libertine} 
\usepackage{array}
\newlength{\period}

\newcommand{\tabfig}{\fontfamily{LinuxLibertineT-TOsF}\selectfont}

\AtBeginDocument{\settowidth{\period}{\tabfig 0000--0000}}

\begin{document}

\begin{tabular}{>{\raggedleft\tabfig}p{\period}l}
2002--2005 & Put some text and numbers 0123456789 here
\end{tabular}

\end{document}

Note the delaying of the measurement after LaTeX has issued \normalfont.

enter image description here

  • Great! Based on this, I assume I can use the same trick with fontspec, i.e. \newcommand{\tabfig}{\newfontfamily{...}} and then use \raggedleft\tabfig? – Sverre Apr 20 '15 at 18:14
  • @Sverre Not certainly with \newfontfamily: \newcommand{\tabfig}{\addfontfeatures{Numbers=Monospaced}} – egreg Apr 20 '15 at 19:38
  • I just tested, and it works fine with \newfontfamily\tabfig[Ligatures = {TeX}, Numbers = {OldStyle, Monospaced}]{Linux Libertine O} for me. I've learned from Khaled Hosny, I believe, that it's better to use \newfontfamily than to use \addfontfeatures. (I don't know what I was thinking in my previous comment suggesting \newcommand etc.). – Sverre Apr 20 '15 at 20:06

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.