Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Why doesn't the \ttdefault change the font in the table? I want to change font for a single table only.

\begin{table}[h!]
\singlespacing
\footnotesize
\ttdefault
\caption{Some caption.}
\label{tab:xxx}\centering
\begin{tabularx}{\textwidth}{XXX}
\toprule
test1 & test2 & test3 \\
test1 & test2 & test3 \\
test1 & test2 & test3 \\
\bottomrule            
\end{tabularx}
\end{table}
share|improve this question
5  
Welcome to TeX.sx! \ttdefault is not a font changing command; you probably want \ttfamily, put it just before the tabularx –  egreg May 4 '13 at 12:35
add comment

1 Answer

up vote 3 down vote accepted

If you need to have the entire table, including the caption, typeset in monospaced font, you can achieve this by inserting the sequence

\renewcommand{\familydefault}{\ttdefault}\normalfont

immediately following the \begin{table} instruction:

\documentclass{article}
\begin{document}
\begin{table}
  \renewcommand{\familydefault}{\ttdefault}\normalfont
  \caption{The table's caption} \label{tab:tt}
  \centering
  \begin{tabular}{cc}
  \hline
  Header 1 & Header 2 \\ \hline
  1 & 2\\ \hline
  \end{tabular}
\end{table}
\end{document}

enter image description here

share|improve this answer
2  
The braces around the macro to be redefined can be omitted, but those around the replacement text shouldn't. Omitting them works in this case, but only because of the current implementation of \renewcommand; don't trust on it forever. –  egreg May 4 '13 at 15:31
    
@egreg - thanks! –  Mico May 4 '13 at 15:32
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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