Hi All,
I was wondering if there was a way to change the Font type within the table environments. For instance, I just wish to change text and data within tables to a Courier New font. Is there a way I can do this with a global command?
Any feedback would be most appreciated, thanks!
LaTeX forum ⇒ Fonts & Character Sets ⇒ Changing Font Type Within Tables
Changing Font Type Within Tables
Hi workerbee,
You could declare a new environment, which changes the font and then calls the standard tabular environment. e.g.
I hope I could help!
Skazz
You could declare a new environment, which changes the font and then calls the standard tabular environment. e.g.
\documentclass{article} \usepackage[utf8]{inputenc} \newenvironment{tttabular}[1]% {\ttfamily \begin{tabular}{#1}}% {\end{tabular}} \begin{document} \begin{tttabular}{c|c|c|c|c|c|c|} the &brown &fox &jumps &over &the &fence\\ over &the &fence &the &brown &fox &jumps \end{tttabular} \end{document}
I hope I could help!
Skazz
Re: Changing Font Type Within Tables
Thanks, Skazz! It works wonderfully.
I was also wondering if there was a way to do this without having to define a new environment--maybe a similar way in how we can change line spacing in the itemize environment using the enumitem package.
I was also wondering if there was a way to do this without having to define a new environment--maybe a similar way in how we can change line spacing in the itemize environment using the enumitem package.
- localghost
- Site Moderator
- Posts: 9201
- Joined: Fri Feb 02, 2007 12:06 pm
Changing Font Type Within Tables
workerbee wrote:[…] I was also wondering if there was a way to do this without having to define a new environment--maybe a similar way in how we can change line spacing in the itemize environment using the enumitem package.
Answering to a very similar request in a German forum, I stumbled upon a very elegant solution by Axel Sommerfeldt (our fellow member sommerfee).
\documentclass[11pt,a4paper,english]{article} \usepackage[T1]{fontenc} \usepackage[utf8]{inputenc} \usepackage{babel} \usepackage[font=small,labelfont=bf,tableposition=top]{caption} \makeatletter % Axel Sommerfeldt [2007/01/07] \providecommand*\AtBeginEnvironment[1]{% \@ifundefined{#1}% {\@latex@error{Environment #1 undefined}\@ehc \@gobble}% {\@ifundefined{ABE@env@#1}% {\expandafter\let\csname ABE@env@#1\expandafter\endcsname \csname #1\endcsname \expandafter\let\csname ABE@hook@#1\endcsname\@empty \@namedef{#1}{\@nameuse{ABE@hook@#1}\@nameuse{ABE@env@#1}}}% {}% \expandafter\g@addto@macro\csname ABE@hook@#1\endcsname}} \@onlypreamble\AtBeginEnvironment \makeatother \AtBeginEnvironment{tabular}{\ttfamily} \begin{document} \begin{table}[!ht] \caption{A Table}\label{tab:table} \centering \begin{tabular}{cc}\hline Table Head & Table Head \\ \hline A Value & A Value \\ A Value & A Value \\ A Value & A Value \\ \hline \end{tabular} \end{table} \end{document}
This is a universal solution since it works with every environment.
Best regards
Thorsten
LaTeX Community Moderator
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes
¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes
¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1
Re: Changing Font Type Within Tables
Thanks, Thorsten!
Changing Font Type Within Tables
Simpler solution:
\usepackage{etoolbox} \AtBeginEnvironment{tabular}{\sffamily} % Changes all tabular environments to sans-serif
Return to “Fonts & Character Sets”
Who is online
Users browsing this forum: No registered users and 2 guests