On the effect of \mathstrut

The macro \mathstrut inserts an invisible box with the height and depth of ( and zero width. You can visualize this effect using a nice package called lua-visual-debug. It requires you to compile the document with LuaTeX though. I have added

\usepackage{lua-visual-debug}

to the preamble and changed

$\mathstrut\x\y$ -> $\x\mathstrut\y$

to put the strut in the middle between the two letters. Generally you should put always put the strut in the beginning because it can disrupt your spacing otherwise. The result is

enter image description here

The faint grey boxes around the lines give an indication of the height and depth of the line and the grey vertical bar in the middle is the strut.


As we see the right hand side figure has some characters up and down with respect to the base line of the left hand side figure in which we used the \mathstrut. To see how we can align the characters on the right hand side the same as what we have in left hand side we can add a parenthesis at the beginning of each text in each block to appreciate the effect of the \mathstut as an invisible parenthesis:

enter image description here

And here is the code:

\documentclass{standalone}
\usepackage{tikz}
 \begin{document}
\begin{tikzpicture}[x=0.75cm,y=0.75cm]
\foreach \x [count=\xi] in {a,...,e}
\foreach \y [count=\yi] in {\x,...,e}
\node [draw, top color=white, bottom color=blue!50, minimum size=0.666cm]
at (\xi,-\yi) {$\mathstrut\x\y$};
\foreach \x [count=\xi] in {a,...,e}
\foreach \y [count=\yi] in {\x,...,e}
\node [draw, top color=white, bottom color=blue!50, minimum size=0.666cm]
at (\xi+5,-\yi) {$(\x\y$};
\draw [red][|-|] (1,-1.14) -- ++(9,0);
\draw [red][|-|] (1,-1.77) -- ++(9,0);
\draw [red][|-|] (1,-2.14) -- ++(9,0);
\draw [red][|-|] (1,-2.77) -- ++(9,0);
\end{tikzpicture}
\end{document}

Tags:

Tikz Pgf

Strut