# How to automatically use typewriter font in arrays?

TeX - LaTeX Asked by NilsK on December 4, 2020

I’m trying to write a script on formal logic. The source code looks something like this:

some text...

[
begin{array}[]{c | c}
p   &   (lnot p) \ hline
1   &   0 \
0   &   1 \
end{array}
]

some more text...


How can I make it, that the text inside the array is written in typewriter font? I tried something like this, which works fine:

[
begin{array}[]{c | c}
texttt{p}   &   texttt{($lnot$ p)} \ hline
texttt{1}   &   texttt{0} \
texttt{0}   &   texttt{1} \
end{array}
]


The problem is, that it is much work and not dynamic. So if I would like to change it back to a normal font, I would need to remove everything myself. Is there an elegant solution to this?

Thank you!

Something like this?

documentclass{article}
usepackage{array} % for 'newcolumntype' macro
newcolumntype{T}{>{ttfamily}c}

begin{document}
begin{center}
begin{tabular}{ T | T }
p  & ($lnot$p) \
hline
1  & 0 \
0  & 1 \
end{tabular}
end{center}
end{document}


Since ttfamily is a text-mode command, I suggest employing a tabular environment rather than an array environment.

Correct answer by Mico on December 4, 2020

I think you might have an XY-problem here.

With many OpenType fonts, you would be able to use the command

addfontfeatures{Numbers={Monospaced,Lining}}


to get fixed-width numbers in a more-attractive font. You might wrap this in an environment, such as:

newenvironment{arraymono}%
{end{array}endgroup}


You might also find the Unicode figure space, which is exactly as wide as a tabular digit, useful here:

newcommandfigspace{^^^^2007}


Answered by Davislor on December 4, 2020

## Related Questions

### Compile only specific part of document (depending on main language)

0  Asked on July 23, 2021

### Hyperref + url: long URL with dashes won’t break

2  Asked on July 23, 2021 by texnic

### Adding arrows outside of plot area and aligning plots

1  Asked on July 23, 2021

### unwanted page break in multilanguage document

1  Asked on July 23, 2021 by awan

### Converting numbers to letters, but starting with 0=A instead of 1=A

5  Asked on July 23, 2021 by justin-troutman

### Using Asymptote for 3D plots

1  Asked on July 23, 2021 by habib-ayati

### Plotting functions using domain coloring

1  Asked on July 23, 2021 by burakumin

### Is there a keyboard shortcut to duplicate lines in LyX

1  Asked on July 23, 2021 by lendion

### Is it possible to include several content indexes in a latex project?

0  Asked on July 23, 2021 by juan-francisco-molina-prez

### Genealogytree – Move Nodes closer together

1  Asked on July 23, 2021 by sir-teddy-the-first

2  Asked on July 23, 2021

### Multiple animated boxes with tikz in beamer

1  Asked on July 23, 2021

### Labeled linear program with labeled equations and wide objective function

3  Asked on July 23, 2021 by xammy

### Stretch wide landscape table to fit page

1  Asked on July 23, 2021 by oceanbeach96

### Vector in Component Form

1  Asked on July 23, 2021 by jc1

### “extract” package causes unfinished group

1  Asked on July 22, 2021 by kerrek-sb

### Implement proof environment as normal paragraph, without list

1  Asked on July 22, 2021 by miguel-v-s-frasson

### Problem using aligned

2  Asked on July 22, 2021

### How to define multipart bibliography entries in amsrefs?

0  Asked on July 22, 2021

### In Beamer cannot link/ref/hyperref to a certain slide/frame where a label was placed

1  Asked on July 22, 2021 by amianonim