[Tex/LaTex] How to change font type face only in table environment

fontstables

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}

Best Answer

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