20

I want to create a table in LaTeX, and this table needs to be in typewriter font.

I have found Typesetting Tables with LaTeX, but I don't understand how to use it.

How could I do this?

1
  • 1
    Welcome to TeX.sx! Your question was migrated here from Stack Overflow. Please register on this site, too, and make sure that both accounts are associated with each other, otherwise you won't be able to comment on or accept answers or edit your question.
    – N.N.
    Sep 15, 2011 at 19:12

3 Answers 3

21

If the entire content of your tables, including the caption, needs to be set in typewriter or monospaced font, the following code (to be inserted in your document's preamble) will do the font switching for you transparently:

\makeatletter
\renewenvironment{table}%
  {\renewcommand{\familydefault}{\ttdefault}\selectfont
  \@float{table}}
  {\end@float}
\makeatother

On the other hand, if you want only the "tabular" portion of a table (but not the caption) to be typeset in typewriter font, you're probably best off (i) inserting the command \texttt{%, on a line by itself, right before the \begin{tabular}{...} line and (ii) adding a solitary closing brace, }, immediately after the \end{tabular} instruction. Happy TeXing!

0
12

Use the courier package:

enter image description here

\documentclass{article}
\usepackage{courier}
\begin{document}
Normal font.

\bigskip
\texttt{
 \begin{tabular}{ll}
  table text & in courier\\
  table text & in courier\\
 \end{tabular}
}

\bigskip
Normal font.
\end{document}​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​
2
  • 1
    That doesn't work. When I define the precise width of a column, my compiler shows, for some reason, lots of nonexistent badboxes
    – user19502
    Jun 30, 2013 at 20:55
  • @user19502: Without more details it is difficult to help you. I suggest you post a new question with a fully compilable example that reproduces the problem. You can reference this answer. Jun 30, 2013 at 21:06
3

You could use this to print the table in courier:

\documentclass[a4paper]{article}

\begin{document}

Normal.

\begin{table}[ht!]
 \fontfamily{pcr}\selectfont
 \begin{tabular}{ll}
  table text & in courier\\
 \end{tabular}
\end{table}

Back to normal.

\end{document}
2
  • 10
    Or simply switch to \ttfamily.
    – Caramdir
    Sep 15, 2011 at 4:25
  • 2
    Just to clarify @Caramdir's suggestion: that is, use \ttfamily rather than \fontfamily{pcr}\selectfont. The former, unlike the latter, will ensure that the current typewriter font is used, even if the preamble is changed to use a different set of fonts. I.e. more flexible as well as simpler.
    – cfr
    Jun 23, 2018 at 1:46

You must log in to answer this question.