2
$\begingroup$

I am preparing some sheets with Boolean expression identies using TableForm's like the following:

TableForm[
 Reverse[Boole[BooleanTable[
    {a, b, Implies[a, b], Or[Not[a], b], Implies[Not[b], Not[a]]},
    {a, b}]]],
 TableHeadings -> {None, {"P", "Q", "P => Q", "\[Not]P \[Or] Q", 
    "\[Not]Q => \[Not]P"}}
 ]

The output of the function above is however not entirely what I want. Ideally I would like to see a vertical divider line to the right of the second ("Q") column.

How can I add this vertical dividerline?

Perhaps I ask too much of Tableform, so I went to Grid:

Grid[
 Reverse[Boole[BooleanTable[
    {a, b, Implies[a, b], Or[Not[a], b], Implies[Not[b], Not[a]]},
    {a, b}]]]
 ]

But that puts me back to figuring out how to add columnheaders, and a nice horizontal dividerline.

( updated 09:31 )

$\endgroup$

1 Answer 1

5
$\begingroup$

Ideally I would like to see a vertical divider line to the right of the second ("Q") column.

Instead of

TableForm[
 Reverse[Boole[BooleanTable[
    {a, b, Or[And[Not[a], b], b]},
    {a, b}]]],
 TableHeadings -> {None, {"P", "Q", "\[Not]P \[And] Q \[Or] Q"}}
]

Mathematica graphics

You can do

data = Reverse[
  Boole[BooleanTable[{a, b, Or[And[Not[a], b], b]}, {a, b}]]]
header = {"P", "Q", "\[Not]P \[And] Q \[Or] Q"};
Grid[Prepend[data, header], 
 Dividers -> {{False, False, True}, {False, True}}, 
 Spacings -> {1, 1}]

Mathematica graphics

And if you want the alignment left as with table

Grid[Prepend[data, header], 
 Dividers -> {{False, False, True}, {False, True}}, 
 Spacings -> {1, 1}, Alignment -> Left]

Mathematica graphics

And if you want to change the style of the vertical lines, you can change FrameStyle

Grid[Prepend[data, header], 
 Dividers -> {{False, False, True}, {False, True}}, 
 Spacings -> {1, 1}, Alignment -> Left, FrameStyle -> Gray]

Mathematica graphics

I find Grid and Dividers easier to work with than TableForm

Updated for the updated question:

You can do the same thing. Instead of

TableForm[
 Reverse[Boole[
   BooleanTable[{a, b, Implies[a, b], Or[Not[a], b], 
     Implies[Not[b], Not[a]]}, {a, b}]]], 
 TableHeadings -> {None, {"P", "Q", "P => Q", "\[Not]P \[Or] Q", 
    "\[Not]Q => \[Not]P"}}]

Mathematica graphics

You can use Grid

data = Reverse[
  Boole[BooleanTable[{a, b, Implies[a, b], Or[Not[a], b], 
     Implies[Not[b], Not[a]]}, {a, b}]]]
header = {"P", "Q", "P => Q", "\[Not]P \[Or] Q", "\[Not]Q => \[Not]P"};
Grid[Prepend[data, header], 
 Dividers -> {{False, False, True}, {False, True}}, 
 Spacings -> {1, 1/2}, Alignment -> Left, FrameStyle -> Gray]

Mathematica graphics

$\endgroup$
7
  • $\begingroup$ What happened to the 4th and 5th column, I wonder ? ( My bad, I'll update the question. )- So this is not possible with TableForm? I suppose it must be Grid then, thank you. $\endgroup$ Nov 26, 2021 at 8:28
  • $\begingroup$ @niloderoock what 4th and 5th column? Your table only has 3 columns? You might be able to add the vertical line with TableForm. I do not know. I use Grid myself. $\endgroup$
    – Nasser
    Nov 26, 2021 at 8:31
  • $\begingroup$ Sorry! I updated the Q. The grid though has 5 columns. $\endgroup$ Nov 26, 2021 at 8:33
  • 1
    $\begingroup$ @niloderoock fyi, updated, $\endgroup$
    – Nasser
    Nov 26, 2021 at 8:35
  • 1
    $\begingroup$ @niloderoock Yes. That is what I meant. Combination of Grid + Dividers gives you what TableForm does but easier to adjust and play around. $\endgroup$
    – Nasser
    Nov 26, 2021 at 8:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.