AnswerBun.com

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!

2 Answers

Something like this?

enter image description here

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}%
  {begingroupaddfontfeatures{Numbers={Monospaced,Lining}}begin{array}}%
  {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

Add your own answers!

Related Questions

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

   

Genealogytree – Move Nodes closer together

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

   

Set language metadata for Adobe

2  Asked on July 23, 2021

   

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

   

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP, SolveDir