TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top
\documentclass[a4paper,12pt]{report}

\usepackage{tikz}
\usetikzlibrary{matrix}

\begin{document}

\begin{center}
\begin{tikzpicture}

\tikzset{square matrix/.style={
    matrix of nodes,
    column sep=-\pgflinewidth, row sep=-\pgflinewidth,
    nodes={draw,
      text height=#1/2+0.75ex,
      text depth=#1/2-0.75ex,
      text width=#1,
      align=center,
      inner sep=0pt
    },
  },
  square matrix/.default=1.4cm
}

\matrix[square matrix]
{
|[fill=lightgray]|+ & |[fill=lightgray]|0 & |[fill=lightgray]|1 & |[fill=lightgray]|$\ldots$ &  |[fill=lightgray]|$\alpha^{2^m-3}$ & |[fill=lightgray]|$2^m - 1$\\
|[fill=lightgray]|0 & 0 & 1 & $\ldots$ &  $2^m - 2$ & $2^m - 1$\\
|[fill=lightgray]|1 & 1 & 0 & $\ldots$ &  $2^m - 2$ + 5465 1\\
|[fill=lightgray]|$\vdots$\\
|[fill=lightgray]|$2^m - 2$\\
|[fill=lightgray]|$2^m - 1$\\
};

\end{tikzpicture}
\end{center}

\end{document}

And output is:

output

Text in the right-bottom cell doesn't fit into cell. How to set vertical align of cell to center which will move this text a bit higher and it will fit into cell?

share|improve this question
up vote 5 down vote accepted

You should use

minimum height=#1,
anchor=center

instead of

text height=#1/2+0.75ex,
text depth=#1/2-0.75ex

This will make sure the text is vertically centered.

\documentclass[a4paper,12pt]{report}

\usepackage{tikz}
\usetikzlibrary{matrix}

\begin{document}

\begin{center}
\begin{tikzpicture}

\tikzset{square matrix/.style={
    matrix of nodes,
    column sep=-\pgflinewidth, row sep=-\pgflinewidth,
    nodes={draw,
      minimum height=#1,
      anchor=center,
      text width=#1,
      align=center,
      inner sep=0pt
    },
  },
  square matrix/.default=1.45cm
}

\matrix[square matrix]
{
|[fill=lightgray]|+ & |[fill=lightgray]|0 & |[fill=lightgray]|1 & |[fill=lightgray]|$\ldots$ &  |[fill=lightgray]|$\alpha^{2^m-3}$ & |[fill=lightgray]|$2^m - 1$\\
|[fill=lightgray]|0 & 0 & 1 & $\ldots$ &  $2^m - 2$ & $2^m - 1$\\
|[fill=lightgray]|1 & 1 & 0 & $\ldots$ &  $2^m - 2$ + 5465 1\\
|[fill=lightgray]|$\vdots$\\
|[fill=lightgray]|$2^m - 2$\\
|[fill=lightgray]|$2^m - 1$\\
};

\end{tikzpicture}
\end{center}

\end{document}

more complex square tikz matrix

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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