我有以下代码:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
[karl/.style ={help lines,color=blue!50}]
\filldraw[step=.5cm,karl] (-1.4,-1.4) grid (1.4,1.4);
[scheme/.style ={draw, rounded corners}]
\draw[scheme] (-0.9,-1) rectangle (1,0.9);
\end{tikzpicture}
\end{document}
第一部分有效,“karl”样式得到正确定义并且网格呈蓝色。
第二部分不起作用,LaTeX 抱怨:
ERROR: Package pgfkeys Error: I do not know the key '/tikz/scheme' and I am going to ignore it. Perhaps you misspelled it.
不过,“圆角”本身确实有效:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
[karl/.style ={help lines,color=blue!50}]
\filldraw[step=.5cm,karl] (-1.4,-1.4) grid (1.4,1.4);
\draw[rounded corners] (-0.9,-1) rectangle (1,0.9);
\end{tikzpicture}
\end{document}
我如何制作一种包含圆角的样式?
答案1
样式定义是tikzpicture
环境的一个选项,您不应该在环境中放置两个可选参数 [...] [...],而应该只放置一个用逗号分隔的样式。
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[karl/.style ={help lines,color=blue!50},
scheme/.style ={draw, rounded corners}]
\filldraw[step=.5cm,karl] (-1.4,-1.4) grid (1.4,1.4);
\draw[scheme] (-0.9,-1) rectangle (1,0.9);
\end{tikzpicture}
\end{document}
如果您的样式对所有环境都有效tikzpicture
,则可以使用\tikzset
:
\documentclass{article}
\usepackage{tikz}
\tikzset{
karl/.style ={help lines,color=blue!50},
scheme/.style ={draw, rounded corners}
}
\begin{document}
\begin{tikzpicture}
\filldraw[step=.5cm,karl] (-1.4,-1.4) grid (1.4,1.4);
\draw[scheme] (-0.9,-1) rectangle (1,0.9);
\end{tikzpicture}
\end{document}