尝试使用 TikZ 来让图形的上下被括号包围,结果非常丑陋:括号以及节点看起来渲染效果很差,因为它们的光栅化存在问题。
以下是代码:
\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}
我已经制作了很多具有相同配置的其他图形,没有任何问题。
答案1
欢迎!
- 正如指出的那样这个答案,有
calligraphic brace
专门针对此的。 - 绝不调用宏
\end
,如中所示\pgfmathsetmacro{\end}{\i + 1.2};
。你很幸运你的代码能工作(因为你在循环中实现了这个)。(;
也是多余的。)特别是,如果不需要宏,如 Ti钾Z 正在解析其表达式。 - 你多次绘制了括号,因为它在循环中。没有必要。我怀疑部分依赖于查看器的丑陋来自于添加括号的次数太多。
- 您不需要
ifthen
norintcalc
软件包。长期来看,如果您继续这种做法,您会遇到困难。 - 您可以使用该
3d
库将文本投影到平面上。
以下是带有书法括号的修改后的代码。
\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}