[Tex/LaTex] How to change font type in tabularx

fontstabularx

How to change one table column in other font type, I need to change all left column. For example from normal to Consolas font. My tabularx:

\begin{table}[ht]
  \centering
  \begin{tabularx}{\textwidth}{|l|X|} \hline
      {\bf wow} &  {\bf nice}  \\ \hline 
      cool &  yey!  \\ \hline
  \end{tabularx}
\end{table}

Best Answer

Do you mean something like this:

enter image description here

For this you need to column type add >{\ttfamily}:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{lmodern}

\usepackage{tabularx}

\usepackage[active,floats,tightpage]{preview}% <-- Only show only table.
                                             % Don't use in +real document! 
\setlength\PreviewBorder{1em}

\begin{document}
\begin{table}[h]
\centering
\begin{tabularx}{\textwidth}{|>{\ttfamily}l|X|}
\hline
\textbf{wow}    &  \textbf{nice}  \\ \hline
cool            &  yey!  \\ \hline
\end{tabularx}
\end{table}\end{document}

(if you with "Console" type mean Typewriter's font).

Edit: Regarding your comment about For centering of column heads: fpor this you have more possibilities:

  • use \multicolumn{1}{c}{\textbf{head text>}}
  • add makecell package and use macro thead{.....}. For font in it you need to redefine the theadfont: \renewcommand\theadfont{\bfseries}.

Complete code:

\documentclass{article}
    \usepackage[T1]{fontenc}
    \usepackage{lmodern}

    \usepackage{makecell,tabularx}
\renewcommand\theadfont{\bfseries}

\usepackage[active,floats,tightpage]{preview}
\setlength\PreviewBorder{1em}

\begin{document}
    \begin{table}[h]
    \centering
\begin{tabularx}{\textwidth}{|>{\ttfamily}l|X|}
\hline
\thead{wow}    &  \thead{nice}  \\ \hline
cool           &  yey!  \\ \hline
\end{tabularx}
    \end{table}
\end{document}

enter image description here

Related Question