尝试构建以下示例时出现三个错误(使用从 tikz pgf 手册中获取的 tikzpicture)。为什么会发生这种情况?我做错了什么?
\documentclass[12pt]{article}
\usepackage{tikz}
\begin{document}
\begin{figure}
\begin{tikzpicture}
[Karl's grid/.style ={help lines,color=#1!50},
Karl's grid/.default=blue]
\draw[Karl's grid] (0,0) grid (1.5,2);
\draw[Karl's grid=red] (2,0) grid (3.5,2);
\end{tikzpicture}
\end{figure}
\end{document}
以下是包含错误的部分日志:
[Loading MPS to PDF converter (version 2006.09.02).]
\scratchcounter=\count107
\scratchdimen=\dimen148
\scratchbox=\box35
\nofMPsegments=\count108
\nofMParguments=\count109
\everyMPshowfont=\toks24
\MPscratchCnt=\count110
\MPscratchDim=\dimen149
\MPnumerator=\count111
\everyMPtoPDFconversion=\toks25
)
Missing character: There is no [ in font nullfont!
Missing character: There is no K in font nullfont!
Missing character: There is no a in font nullfont!
Missing character: There is no r in font nullfont!
Missing character: There is no l in font nullfont!
Missing character: There is no ' in font nullfont!
Missing character: There is no s in font nullfont!
Missing character: There is no g in font nullfont!
Missing character: There is no r in font nullfont!
Missing character: There is no i in font nullfont!
Missing character: There is no d in font nullfont!
Missing character: There is no / in font nullfont!
Missing character: There is no . in font nullfont!
Missing character: There is no s in font nullfont!
Missing character: There is no t in font nullfont!
Missing character: There is no y in font nullfont!
Missing character: There is no l in font nullfont!
Missing character: There is no e in font nullfont!
Missing character: There is no = in font nullfont!
Missing character: There is no h in font nullfont!
Missing character: There is no e in font nullfont!
Missing character: There is no l in font nullfont!
Missing character: There is no p in font nullfont!
Missing character: There is no l in font nullfont!
Missing character: There is no i in font nullfont!
Missing character: There is no n in font nullfont!
Missing character: There is no e in font nullfont!
Missing character: There is no s in font nullfont!
Missing character: There is no , in font nullfont!
Missing character: There is no c in font nullfont!
Missing character: There is no o in font nullfont!
Missing character: There is no l in font nullfont!
Missing character: There is no o in font nullfont!
Missing character: There is no r in font nullfont!
Missing character: There is no = in font nullfont!
! You can't use `macro parameter character #' in restricted horizontal mode.
l.24 [Karl's grid/.style ={help lines,color=#
1!50},
Sorry, but I'm not programmed to handle this case;
I'll just pretend that you didn't ask for it.
If you're in the wrong mode, you might be able to
return to the right one by typing `I}' or `I$' or `I\par'.
Missing character: There is no 1 in font nullfont!
Missing character: There is no ! in font nullfont!
Missing character: There is no 5 in font nullfont!
Missing character: There is no 0 in font nullfont!
Missing character: There is no , in font nullfont!
Missing character: There is no K in font nullfont!
Missing character: There is no a in font nullfont!
Missing character: There is no r in font nullfont!
Missing character: There is no l in font nullfont!
Missing character: There is no ' in font nullfont!
Missing character: There is no s in font nullfont!
Missing character: There is no g in font nullfont!
Missing character: There is no r in font nullfont!
Missing character: There is no i in font nullfont!
Missing character: There is no d in font nullfont!
Missing character: There is no / in font nullfont!
Missing character: There is no . in font nullfont!
Missing character: There is no d in font nullfont!
Missing character: There is no e in font nullfont!
Missing character: There is no f in font nullfont!
Missing character: There is no a in font nullfont!
Missing character: There is no u in font nullfont!
Missing character: There is no l in font nullfont!
Missing character: There is no t in font nullfont!
Missing character: There is no = in font nullfont!
Missing character: There is no b in font nullfont!
Missing character: There is no l in font nullfont!
Missing character: There is no u in font nullfont!
Missing character: There is no e in font nullfont!
Missing character: There is no ] in font nullfont!
! Package pgfkeys Error: I do not know the key '/tikz/Karl's grid' and I am goi
ng to ignore it. Perhaps you misspelled it.
See the pgfkeys package documentation for explanation.
Type H <return> for immediate help.
...
l.27 \draw[Karl's grid]
(0,0) grid (1.5,2);
This error message was generated by an \errmessage
command, so I can't give any explicit help.
Pretend that you're Hercule Poirot: Examine all clues,
and deduce the truth by order and method.
! Package pgfkeys Error: I do not know the key '/tikz/Karl's grid' and I am goi
ng to ignore it. Perhaps you misspelled it.
See the pgfkeys package documentation for explanation.
Type H <return> for immediate help.
...
l.29 \draw[Karl's grid=red]
(2,0) grid (3.5,2);
(That was another \errmessage.)
我正在使用 tikz 2010/10/13 v2.10(rcs-revision 1.76),并且在 Windows XP 上结合使用 MikTex 与 Texniccenter。
答案1
问题是由您打开环境后出现的空行引起的tikzpicture
。请注意,空行通常表示段落中断,因此请不要仅仅为了可读性而在文档代码中使用它。如果您想使用(几乎)空行进行分隔,请在行中设置至少一个 % 以将其注释掉。
它的工作方式如下:
\begin{tikzpicture}
[Karl's grid/.style ={help lines,color=#1!50},
Karl's grid/.default=blue]
答案2
补充答案
\documentclass{article}
\begin{document}
\section{Test 1}
This new line:
will become a space in this statement.
\section{Test2}
This new line + empty line:
will become a new paragraph in this statement.
\section{Test 3}
This new line + non-indented \%:
%
will become a space in this statement.
\section{Test 4}
This new line + indented \%:
%
will become a space in this statement.
\end{document}