# How to improve poorly rendered braces around TikZ figure?

Trying with TikZ to have a figure surrounded by braces above and below, the result is quite ugly: braces as well as node besides look poorly rendered, as it there was a problem in their rasterization.

Here is the code:

\documentclass{scrartcl}
\usepackage{xcolor}
\usepackage{ifthen}
\usepackage{intcalc}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing}

\begin{document}

\begin{tikzpicture}
\pgfmathsetmacro{\nlength}{12}
\pgfmathsetmacro{\mlength}{4}
\foreach \i in {-1,...,\nlength} {
\pgfmathsetmacro{\end}{\i + 1.2};
\pgfmathsetmacro{\mid}{\i + 0.6};
\newcommand\drawColor{black}
\newcommand\fillColor{white}
\newcommand\elementClass{B}
\ifthenelse
{\equal{\intcalcMod{\i}{\nlength}}{0}}
{%
\renewcommand\drawColor{red!80!white}
\renewcommand\fillColor{red!80!white}
\renewcommand\elementClass{I}
}%
{\ifthenelse%
{\equal{\intcalcMod{\i}{\mlength}}{0}}
{
\renewcommand\drawColor{red!40!white}
\renewcommand\fillColor{red!40!white}
\renewcommand\elementClass{P}
}{}%
}
\draw[\drawColor,fill=\fillColor] (\i, 0) -- (\end, 1) -- (\end, -1) -- (\i, -2) -- (\i, 0);
\node at (\mid, -0.6) {\elementClass};
\draw[decorate, decoration={brace, amplitude=10pt, raise=5pt}] (0.6, 1) -- (\nlength, 1) node [rectangle, draw=black, midway, yshift=1cm, font=\small] {$N = \nlength$};
\draw[decorate, decoration={brace, amplitude=10pt, raise=5pt, mirror}] (0.6, -2) -- (\mlength, -2) node [rectangle, draw=black, midway, yshift=-1cm, font=\small] {$M = \mlength$};
}
\end{tikzpicture}

\end{document}


I've made lots of other figures with the same configuration without any problem.

Welcome!

1. As pointed out in this answer, there is the calligraphic brace specifically for that.
2. Never call a macro \end as done in \pgfmathsetmacro{\end}{\i + 1.2};. You were very lucky that your code worked (because you had this in the loop). (The ; are superfluous, too.) In particular, if the macro is not needed, as TikZ is parsing its expression.
3. You draw the brace many times because it is in the loop. Not needed. I suspect that part of the viewer-dependent ugliness comes from adding the brace so many times.
4. You do not need the ifthen nor intcalc packages. On the long run you will encounter difficulties if you continue this practice.
5. You can use the 3d library to project the texts on the planes.

Here is the revised code with a calligraphic brace.

\documentclass{scrartcl}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing,calligraphy,3d}
\begin{document}
\begin{tikzpicture}
\pgfmathsetmacro{\nlength}{12}
\pgfmathsetmacro{\mlength}{4}
\foreach \i in {-1,...,\nlength} {
\newcommand\drawColor{black}
\newcommand\fillColor{white}
\newcommand\elementClass{B}
\pgfmathtruncatemacro{\itest}{Mod(\i,\nlength)}
\ifnum\itest=0
\renewcommand\drawColor{red!80!white}
\renewcommand\fillColor{red!80!white}
\renewcommand\elementClass{I}
\else
\pgfmathtruncatemacro{\jtest}{Mod(\i,\mlength)}
\ifnum\jtest=0
\renewcommand\drawColor{red!40!white}
\renewcommand\fillColor{red!40!white}
\renewcommand\elementClass{P}
\fi
\fi
\begin{scope}[canvas is zy plane at x=\i]
\draw[\drawColor,fill=\fillColor] (-1,-1) rectangle (1,1);
\path (0,0) node[transform shape,xscale=-1] {\elementClass};
\end{scope}
}
\draw[decorate, decoration={calligraphic brace, amplitude=10pt,
raise=5pt},line width=1pt] (0, 1.4) -- (\nlength-0.6, 1.4) node [rectangle, draw=black, midway, yshift=1cm, font=\small] {$N = \nlength$};
\draw[decorate, decoration={calligraphic brace, amplitude=10pt,
raise=5pt, mirror},line width=1pt] (0, -1.4) -- (\mlength-0.6, -1.4) node [rectangle,
draw=black, midway, yshift=-1cm, font=\small] {$M = \mlength$};
\end{tikzpicture}
\end{document}


• Perfect solution to the question and the other ones I hadn't seen, thanks a lot! – bmrs Nov 8 at 22:43
• @bmrs You're welcome! – Schrödinger's cat Nov 8 at 23:16