0

How to make in math mode a tabu whose cells have fixed height and width, in particular they have to be squared, and such that the content is centered in each cell?

Initially this was my table

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath,amsfonts,amssymb,mathtools}
\usepackage{xcolor,tabu}

\newcommand\cred[1]{{\color{red}#1}}

\begin{document}

$\begin{tabu}{|c|[1pt]c|c|}
\hline
\cred+ & \cred0 & \cred1 \\
\tabucline[1pt]{-}
\cred0 & 0 & 1 \\
\hline
\cred1 & 1 & \int_0^1 10 \\
\hline
\end{tabu}$

\end{document}

enter image description here

In the official documentation I read that it is possibile to specify the target width of the whole tabular by writing {tabu} to (dimen), but this imply to modify the tabular preamble by using X[coef,align,type]. But what about the height?

This is the current version of the table

$\begin{tabu} to 0.3\textwidth {| X[c] |[1pt] X[c] | X[c] |}
\hline
\cred+ & \cred0 & \cred1 \\
\tabucline[1pt]{-}
\cred0 & 0 & 1 \\
\hline
\cred1 & 1 & \int_0^1 10 \\
\hline
\end{tabu}$

enter image description here

I don't understand why the colored numbers are so low, and also why the cell containing the integral is broken.

  • 2
    Before continuing to use tabu read the readme here github.com/tabu-issues-for-future-maintainer/tabu – Ulrike Fischer Aug 27 '19 at 14:39
  • Thanks for letting me know about those problems, so is the problem solvable or I have to switch from tabu to another environment? – sound wave Aug 27 '19 at 15:02
  • 1
    I have no idea. I don't answer or investigate questions with tabu anymore because of its state. – Ulrike Fischer Aug 27 '19 at 15:14
  • Ok I understand, if you know how to solve the problem with tabular or something else of your choice I will be pleased to learn it – sound wave Aug 27 '19 at 15:17
  • 1
    You can draw this table with tikz using matrix library` . – Zarko Aug 27 '19 at 15:25
3

Let mi elaborate my comment:

enter image description here

\documentclass[tikz, margin=3pt]{standalone}
\usetikzlibrary{matrix}
\usepackage{nccmath}

\begin{document}
\begin{tikzpicture}
  \matrix [matrix of math nodes,
           nodes={draw, minimum size=3em,
                  inner sep=0pt, outer sep=0pt, anchor=center},
           column sep=-\pgflinewidth,
           row sep=-\pgflinewidth,
           column 1/.append style={nodes={text=red}},
           row 1/.append style={nodes={text=red}},
           ]
{
+   &   0   &   1   \\
0   &   0   &   1   \\
1   &   1   &   \medint\int_0^1 10 \\ 
}; 
\end{tikzpicture}
\end{document}

Addendum: if you like coloring column's and row's bacgroun you only need ad fil=<desired color> to col 1/.append style and row 1/.append style:

\documentclass[tikz, margin=3pt]{standalone}
\usetikzlibrary{matrix}
\usepackage{nccmath}

\begin{document}
\begin{tikzpicture}
  \matrix [matrix of math nodes,
           nodes={draw, minimum size=3em,
                  inner sep=0pt, outer sep=0pt, anchor=center},
           column sep=-\pgflinewidth,
           row sep=-\pgflinewidth,
           column 1/.append style={nodes={text=red,fill=gray!20}},
           row 1/.append style={nodes={text=red,fill=gray!20}},
           ]
{
+   &   0   &   1   \\
0   &   0   &   1   \\
1   &   1   &   \medint\int_0^1 10 \\
};
\end{tikzpicture}
\end{document}

enter image description here

  • 1
    You could use minimum height=4em, t make the table cells square as the OP requested. – leandriis Aug 27 '19 at 18:29
  • 2
    @leandriis, you are right ... OP wont square cells. I would correct answer asap! – Zarko Aug 27 '19 at 18:32
  • @Zarko thank you very much, is it possibile to color the background of the column 1 and row 1? – sound wave Aug 28 '19 at 13:39
  • 1
    @soundwave, of course just add `fill=gray!20 to column and row styles. see addendum to my answer. – Zarko Aug 28 '19 at 14:03
  • 1
    @soundwave, no, but it is handy. you can remove it and \medint have ugly integral symbol :-(, or replace \medint with displaystyle and have bigger integral symbol, which will require to increase cells' size (minimum size=3em to for example minimum size=3.4em) – Zarko Aug 28 '19 at 14:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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